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
    Banned
    Join Date
    Jan 2007
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Get value from a <select>

    I was wondering. Is it possible to retrieve the value of a select. I have a select with all the months of the year.

    <select name="selection">
    <option>januari</option>
    <option>Februari</option>
    <option>Maart</option>
    <option>April</option>
    <option>Mei</option>
    <option>Juni</option>
    <option>Juli</option>
    <option>Augustus</option>
    <option>September</option>
    <option>Oktober</option>
    <option>Novermber</option>
    <option>December</option>
    </select>

    When someone chooses for instance "februari" I want that value to be given to an <input type="text" name="invoer">

    I tried things like

    invoer.value = selection.value;

    But that did not work. How do I get this value??

    Thanx in advance,

    Zynex
    Last edited by Zynex; 02-19-2007 at 11:26 AM.

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,519
    Thanks
    3
    Thanked 507 Times in 494 Posts
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
    
    <html>
    
    <head>
      <title></title>
    <script language="JavaScript" type="text/javascript">
    <!--
    var MonthAry=['januari','Februari','Maart','April','Mei','Juni','Juli','Augustus','September','Oktober','Novermber','December'];
    
    function Populate(frm,sel,ary){
     for (var zxc0=0;zxc0<ary.length;zxc0++){
      document[frm][sel].options[zxc0+1]=new Option(ary[zxc0],ary[zxc0],true,true);
     }
     document[frm][sel].selectedIndex=0;
    }
    
    function Write(sel,tb){
     sel.form[tb].value=sel.value;
    }
    
    //-->
    </script></head>
    
    <body onload="Populate('MyForm','selection',MonthAry);" >
    
    <form name="MyForm" >
    <select name="selection" onchange="Write(this,'monthtxt');" >
    <option value="" >Select Month</option>
    <input name="monthtxt" type="text" size="10" >
    </select>
    </form>
    </body>
    
    </html>
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/


  •  

    Posting Permissions

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