Newbie needs help! Passing select values to hidden text field...

Discussion in 'Javascript' started by Matt, Jul 21, 2004.

  1. Matt

    Matt Guest

    I know there have to be a million tutorials on this, but I can't seem to
    find any of them. Using onsubmit, how do I pass the value from a select
    menu to a hidden text field? Any help would be greatly appreciated.
     
    Matt, Jul 21, 2004
    #1
    1. Advertising

  2. Matt

    Ivo Guest

    "Matt" wrote
    > I know there have to be a million tutorials on this, but I can't seem to
    > find any of them. Using onsubmit, how do I pass the value from a select
    > menu to a hidden text field? Any help would be greatly appreciated.


    Are you sure you don't want to do this in the serverside script? That is
    always more reliable as users may have no javascript. Anyway, one of a
    million possible approaches:

    <script type="text/javascript">
    function seltohid(el){
    var sel=el.elements['sel'];
    el.elements['hid'].value=sel[sel.selectedIndex].value;
    return true;
    }
    </script>
    </head>
    <body>
    <form name="f" onsubmit="return seltohid(this)">
    <input type="hidden" name="hid" value="">
    <select name="sel">
    <option value="jack">jack
    <option value="john">john
    <option value="mary">mary
    </select>
    <input type="submit">
    </form>

    HTH
    Ivo
     
    Ivo, Jul 21, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rick
    Replies:
    3
    Views:
    8,372
    Alexey Smirnov
    Apr 13, 2010
  2. Jaygo
    Replies:
    2
    Views:
    138
    Jaygo
    Jun 24, 2004
  3. Roy Adams

    writing from hidden field to text field

    Roy Adams, Dec 20, 2004, in forum: Javascript
    Replies:
    1
    Views:
    208
  4. Roy Adams
    Replies:
    3
    Views:
    276
    Dr John Stockton
    Dec 21, 2004
  5. Replies:
    3
    Views:
    169
    OmegaJunior
    Mar 11, 2007
Loading...

Share This Page