I am looking for a way to make sure the value of a control is blank if the control gets hidden. Based on what I have seen so far, if you hide a control, for example a textbox, and you have already typed something in it, when the control gets hidden, the value is still there. I have a lot of conditional logic in the form I am working on, and when the user selects certain options, I need to ensure that the fields that get hidden as a result have their values set to zero.
Here's what I am trying to do basically:
1) Check the value of a field.
2) If the value of the field is "New", then show Textbox A and Textbox B and make sure Textbox C and Textbox D are blank.
3) If the value of the field is "Upgrade", do the opposite of 2.
So I want to be able to do the following with code:
1) show and hide controls based on the value of a field.
2) set the value of a field, based on the value of another field.
I know it can be done with rules and conditional formatting, but I'd rather do it in code if I can.
My biggest problem here is I am not sure how to reference objects on the form within jscript, nor do I know how to reference fields to check their values. I prefer to do as little as possible with rules, etc, and do almost all of this in code. I don't see any really clear cut examples of this anywhere (I am very new to Infopath, so I may be missing it completely).
Is there an efficient way to do these operations in code? I am making the assumption that if a rule can do it or if conditional formatting can do it, it can be done in code. If so can someone please provide an example (I will be using jscript) or point me to some that are out there.
Thanks,
Ryan