Dynamically change variables in FORM without reload page

Discussion in 'HTML & Website Design' started by lu_norman, Sep 9, 2006.

  1. #1
    Hi all!
    How can i do this:

    <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?

    and now: if student="yes" then this boy is a student:

    <input type=hidden name="message1" value="he is a student">
    <input type=hidden name="message2" value="welcome">

    or if student not "yes" this boy is not a student:

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

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

    Thanks
     
    lu_norman, Sep 9, 2006 IP
  2. sketch

    sketch Well-Known Member

    Messages:
    898
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    148
    #2
    This doesn't seem the best way to do it since you're changing hidden values. Simply alter your receiving script to create the values if it detects "yes" or "no". Doing it with Javascript (which is what you'd need to do it on the page without reloading) is a waste if the values are hidden.

    For example, if your receiving script is in PHP, it'd be something like this:

    
    if (isset($_POST['student'])) {
         $msg1 = "he is a student";
         $msg2 = "welcome";
    } else {
         $msg1 = "who is it";
         $msg2 = "bye";
    }
    
    Code (markup):
    Similar code can be used for Perl/CGI ... I just don't know what it is :p
     
    sketch, Sep 9, 2006 IP
  3. frankcow

    frankcow Well-Known Member

    Messages:
    4,859
    Likes Received:
    265
    Best Answers:
    0
    Trophy Points:
    180
    #3
    no, changing hidden values is fine, it's the same as changint the value of any text field
     
    frankcow, Sep 11, 2006 IP