Set a checkbox based on a textbox value - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Set a checkbox based on a textbox value

Last post 08-27-2021 11:58 AM by webwmn53. 15 replies.
Page 1 of 2 (16 items) 1 2 Next >
Sort Posts: Previous Next
  • 09-30-2009 01:28 PM

    • carwil
    • Not Ranked
    • Joined on 08-11-2009
    • Posts 6

    Set a checkbox based on a textbox value

    I am using InfoPath 2003.  How do you set a single check box value to TRUE and others to FALSE based on the value of a text box (whole number)?  An example:  If CALC = 19, then CKBX1 = TRUE, CKBX2 = FALSE, CKBX3 = FALSE, CKBX4 = FALSE.

    It appears to being processing correctly, but does not put the check in the box.  Is there a step I am missing?

    Thank you in advance for your help!

  • 09-30-2009 01:51 PM In reply to

    Re: Set a checkbox based on a textbox value

    Make sure your checkbox control uses TRUE and FALSE for the values of selected / deselected (you can look at the control's properties to find this). Sometimes when I'm troubleshooting something like this, I add an expression box or text box bound to the same field. See what it gets set to when you manually select / deselect the checkbox. Then see what it gets set to when you run your rule. XML is case sensitive, don't forget that, so true does not equal TRUE.

    Hilary Stoupa

  • 10-01-2009 10:30 AM In reply to

    • carwil
    • Not Ranked
    • Joined on 08-11-2009
    • Posts 6

    Re: Set a checkbox based on a textbox value

    Hilary,

    Thank you for your reply. 

    I followed your suggestion and did get TRUE in the text box, but I must be missing something very simple.  The effect that I got in the check boxes was this:  (In Preview Form) TRUE – not checked and I cannot type into the box.  FALSE – not checked, and I can check the other three check boxes.

     

    I am setting the fields on a calculated field.  Should I be doing it here or on the check box itself?  What seems strange to me is that I can see that things are working correctly using a text box bound to the same field.  I have to admit I am stumped.

     

    Thank you!!

     

    This what things look like:

    Condition:   Calc > 19

    Actions:      Set field value: chkbox1 = “TRUE”

                      Set field value: chkbox2 = “FALSE”

                      Set field value: chkbox3 = “FALSE”

                      Set field value: chkbox4 = “FALSE”

     

    The check box properties are set as:

    Data type:  True/False (boolean)

    Default:      Cleared

    Value when cleared:    FALSE

    Value when checked:  TRUE

     

    When I add the rules for check box 2 neither boxes are checked.  This what things look like:

     

    Condition:   Calc > 19

    Actions:      Set field value: chkbox2 = “TRUE”

                      Set field value: chkbox1 = “FALSE”

                      Set field value: chkbox3 = “FALSE”

                      Set field value: chkbox4 = “FALSE”

     

    The check box properties are set as:

    Data type:  True/False (boolean)

    Default:      Cleared

    Value when cleared:    FALSE

    Value when checked:  TRUE

     

     

  • 10-01-2009 02:52 PM In reply to

    Re: Set a checkbox based on a textbox value

    So these rules are all set on some field other than chkbox1, 2, 3, or 4? Is this form something you can share? If so, perhaps attach it to a reply (under the Options tab, there is a place to attach a file). It is usually easier to figure these things out if we can see the form. When you talk about not being able to type in the box, it seems as if you may also have some conditional formatting set up?

    Hilary Stoupa

  • 10-01-2009 03:18 PM In reply to

    • carwil
    • Not Ranked
    • Joined on 08-11-2009
    • Posts 6

    Re: Set a checkbox based on a textbox value

    Hilary,

    Thanks for getting back to me.

    The rules are on a calculated field (which is hidden).  I attempted to share the form, but I get an error, "Malicious Behavior Detected! The page or file you requested contains malicious code. Transaction ID is 4AC519EFA90C080E156F."  So here goes...

    I have a calculated field (Calc) which sums whole numbers.  If the value of the Calc is < 19 I want to set chkbox1 (low) to True and the other three to False.  If calc is between 20-29 I want to set chkbox2 (neutral) to True and the other three to False. If calc is between 30-40 I want to set chkbox3 (high)  to True and the other three to False.  If calc is >40 I want to set chkbox4 (dangerous) to True and the other three to False.

    What I am seeing when I used your testing suggestion is the correct value of the calculation and the correct text so I do know that things are working correctly, but I never get the check in the box.  I did just verify that I do not have any conditional formatting on any of the check boxes.

    I am verifying all of my work in Preview Form, would I possibly see other results if I published the form?

     

  • 10-01-2009 03:44 PM In reply to

    Re: Set a checkbox based on a textbox value

    I've attached a simple sample form to this reply. Right click the link in the header, and save the form locally. Right click the saved copy and open in design mode. Preview to test.

    I only did two rules, one for < 19 and one for >= 19. The top section is for checkboxes -- you'll see that the value I'm setting the fields to is actually a function (click the fx button next to the value field to enter). The true() or false() functions help with pesky case errors.

    In the second section, I show the same thing with a set of option buttons. When your options are mutually exclusive (and it sounds like yours are) and option button control can be a good way to go...

    Hilary Stoupa

  • 10-01-2009 04:38 PM In reply to

    • carwil
    • Not Ranked
    • Joined on 08-11-2009
    • Posts 6

    Re: Set a checkbox based on a textbox value

    Thank you so much for the sample.  It is very helpful.  I know exactly what I did wrong.  I was typing in TRUE and FALSE and did not use the function button to enter the value.

    I believe I will delete the check boxes have and start over.  It seems like the cleanest thing to do using your example.

  • 10-01-2009 05:44 PM In reply to

    Re: Set a checkbox based on a textbox value

    When you have a situation where only one of something should be selected, option buttons are the way to go -- the logic gets a lot simpler, because you are only setting the value of a single field.

    Hilary Stoupa

  • 09-03-2010 07:36 AM In reply to

    Re: Set a checkbox based on a textbox value

    Can the same principle be applied between two check boxes.   If I check one box, it checks another?    I can get the value on the second check box to be 'true', but the box won't show up as 'checked'.   I'm using InfoPath 2007.

    Laurie Wheeler
  • 09-03-2010 07:39 AM In reply to

    Re: Set a checkbox based on a textbox value

    Yes, it should work fine.  Look at the properties of the checkbox you want to automatically check, and make sure that the checked value is true.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 09-03-2010 07:43 AM In reply to

    Re: Set a checkbox based on a textbox value

    Thank...  I see I did have the values flip-flopped.   I just need to add a rule now to turn it back off, when the first check box is un-checked.  Thanks much.

    Laurie Wheeler
  • 09-03-2010 08:04 AM In reply to

    Re: Set a checkbox based on a textbox value

    Why not just use a rule to set the second checkbox to the same value as the first checkbox.  No need for conditions or multiple rules.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 09-03-2010 08:09 AM In reply to

    Re: Set a checkbox based on a textbox value

    In reality... I don't even need the second check box.   I just use a conditional formation on a related text box that I won't want visible until the one check box is checked.  But...  I needed to know how to do this anyway...   I have other section of the form that will require it, where a text box is not involved but check boxes are.
    Laurie Wheeler
  • 09-03-2010 09:42 AM In reply to

    Re: Set a checkbox based on a textbox value

    Ok.....so I guess my advice would apply to the other section that requires the the checkboxes.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 09-03-2010 10:07 AM In reply to

    Re: Set a checkbox based on a textbox value

    Absolutely.
    Laurie Wheeler
Page 1 of 2 (16 items) 1 2 Next >
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.