469,326 Members | 1,359 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,326 developers. It's quick & easy.

Dynamically change variables in FORM whithout reload page

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
1 3481
acoder
16,027 Expert Mod 8TB
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.

Similar topics

3 posts views Thread by Dave Nouwens | last post: by
2 posts views Thread by Ola Fjelddahl | last post: by
10 posts views Thread by Randy Webb | last post: by
8 posts views Thread by Donald Xie | last post: by
2 posts views Thread by Wee Bubba | last post: by
10 posts views Thread by EOZyo | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.