By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,695 Members | 1,580 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,695 IT Pros & Developers. It's quick & easy.

Checkbox populating two text fields in Javascript

P: 2
Hi.

I am using this code so that when a checkbox is selected it populates two separate textfields with the word "No".

Expand|Select|Wrap|Line Numbers
  1.  <script type="text/javascript"><!-- 
  2. function setField(what) {
  3. if (what.regonly.checked)
  4. what.share1.value = 'No';
  5. else
  6. what.share1.value = '';
  7. if (what.regonly.checked)
  8. what.share2.value = 'No';
  9. else
  10. what.share2.value = '';
  11. }
  12. //-->
  13. </script>
  14.  
  15. <input type="checkbox" name="regonly" value="195.00" onClick="setField(this.form)">
  16.  
This works fine, however I want to have a second check box in the same form with a different name (name="regonlypartner") do the same thing if it's selected however if I use the above script again but change to (what.regonlypartner.checked) etc. the first checkbox ceases to function (I now have two scripts on the page).

Can someone show me how to combine this function or create it properly so that either checkbox when selected will fill these two fields?

[I could also use radio buttons as the registrant will only be selecting one type of registration.]

Thanks for your time and help!

Tom
Nov 28 '05 #1
Share this Question
Share on Google+
3 Replies


Expert Mod 100+
P: 2,330
In you second if statement in the javascript code you might want to change "what.regonly.checked" to "what.regonlypartner.checked".

Post back to let us know if it works.
Nov 29 '05 #2

P: 2
Thanks for the reply. It didn't work out.

I made the change to the second section to see if the box would populate with "NO". Ussing this script:

Expand|Select|Wrap|Line Numbers
  1.  <script type="text/javascript"><!-- 
  2. function setField(what) {
  3. if (what.regonly.checked)
  4. what.share1.value = 'No';
  5. else
  6. what.share1.value = '';
  7. if (what.regonlypartner.checked)
  8. what.share1.value = 'No';
  9. else
  10. what.share1.value = '';
  11. }
  12. //-->
  13. </script>
  14.  
The regonly checkbox no longer populates the text box. The regonlypartner does. For some reason it negates the first if statement.

Thanks for the thoughts...
Nov 30 '05 #3

acoder
Expert Mod 15k+
P: 16,027
[I could also use radio buttons as the registrant will only be selecting one type of registration.]
A radio button is more appropriate for this.
Oct 1 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.