Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    OnChange event problem

    Hi All,

    Need a bit of help here, need this SELECT to submit the page and end up at the below URL, correctly passing the GET values through the string.

    <code>
    <select name="dir-fact-misma" id="dir-fact-misma" class="text100" tabindex="" onChange="alta_nueva.action='alta.php?page=p2#alta'; return true;">
    <option value="Si" <?php if(!isset($_POST['dir-fact-misma']) || $_POST['dir-fact-misma'] == 'Si') print "Selected='Selected '"; ?>>Si</option>
    <option value="No" <?php if(isset($_POST['dir-fact-misma']) && $_POST['dir-fact-misma'] == 'No') print "Selected='Selected '"; ?>>No</option>

    </select>
    </code>

    the form in which this SELECT is placed needs to be submitted so that other fields in the form are not lost, they are saved in Session Variables.

    the same javascript but activated through an onclick event works perfect elsewhere in the same form with the following code, i think its the onChange that doesn't work for some reason.

    <code>
    <input name="p1" type='submit' id="p1" onclick="alta_nueva.action='alta.php?page=p1#alta'; return true;" value='1' />
    </code>

    the page is programmed in PHP.

    Any help is appreciated.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,211
    Thanks
    75
    Thanked 4,344 Times in 4,310 Posts
    What is alta_nueva??

    If that is the name of the <form> then you would need to use document.alta_nueva

    But also, if it is the <form> that encloses the given <select> or <input>, then you should be coding it as simply this.form.....

    So:
    Code:
    <select name="dir-fact-misma" class="text100" 
            onchange="this.form.action='alta.php?page=p2#alta'; this.form.submit();">
    There's almost never a reason to give an id to <form> fields. The name is needed, else the field won't be seen by the PHP code. But the id adds nothing useful to the mix.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •