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

Dynamically change variables in FORM whithout reload page

P: 1
Hi all!
How can i do this:

[HTML]<form method="get" action="test.asp" >
<input name="boys" type=radio value="John">John
<input name="boys" type=radio value="Lu">Lu
<input name="boys" type=radio value="James">James
<input name="student" type=checkbox value="yes">student?
[/HTML]
and now: if student=yes then this boy is a student:

[HTML] <input type=hidden name="message1" value="he is a student">
<input type=hidden name="message2" value="welcome">
[/HTML]
or if student not "yes" then boy is not a student:

[HTML] <input type=hidden name="message1" value="who is it">
<input type=hidden name="message2" value="bye">

<input type="submit" value="Ок">
</form>[/html]

Thanks
Sep 9 '06 #1
Share this Question
Share on Google+
1 Reply


acoder
Expert Mod 15k+
P: 16,027
Add an onclick to the checkbox to call a function:
[HTML]<input name="student" type=checkbox value="yes" onclick="isStudent(this)">student?[/HTML]
Add an id to the hidden field for easy access:[HTML] <input id="message1" type=hidden name="message1" value="he is a student">[/HTML]
and now onto the javascript:
Expand|Select|Wrap|Line Numbers
  1. function isStudent(checkbox) {
  2.     var hidden = document.getElementById("message1");
  3.     if (checkbox.checked) {
  4.         hidden.value="this is a student";
  5.     } else {
  6.         hidden.value = "not a student";
  7.     }
  8. }
May 14 '08 #2

Post your reply

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