javascript - How to take selected option from select element in html and use it in js? -
i beginning write code. if wanted have user select option , have document store option chose, how that? example, if chose option 7, how have document write value? thank time!
<p> destination? <select> <option value="mercury">mercury</option> <option value="venus">venus</option> <option value="mars">mars</option> <option value="jupiter">jupiter</option> <option value="saturn">saturn</option> <option value="uranus">uranus</option> <option value="neptune">neptune</option> <option value="pluto">pluto</option> </select> <script type="text/javascript"> var planets = new array(mercury, venus, mars, jupiter, saturn, uranus, neptune, pluto); planets[0] = 48000000 planets[1] = 25000000 planets[2] = 33900000 planets[3] = 365000000 planets[4] = 1200000000 planets[5] = 2600000000 planets[6] = 2800000000 planets[7] = 4600000000 </script> </p>
firs give select element id find by. try this:
var elm = document.getelementbyid('selectbox'); var selectedoption = elm.options[elm.selectedindex].value;
selectedoption contain value selected
Comments
Post a Comment