Get value from a <select>

Discussion in 'JavaScript' started by Zynex, Feb 19, 2007.

  1. #1
    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
     
    Zynex, Feb 19, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    Try
    
    document.getElementByName('invoer').setAttribute('value', document.getElementByName('selection').getAttribute('value'));
    
    Code (javascript):
     
    nico_swd, Feb 19, 2007 IP