javascript - pass value to function in form of <select> -


this question has answer here:

all want pass <select> </select> value javascript function. here code:

function test() {    var gender = document.getelementbyid("gender").value; } 

html

<form action="" method="post" onsubmit="test()">   <select  name="gender" id="gender">      <option selected="" value="default">select</option>      <option value="male">male</option>      <option value="female">female</option>   </select>   </form> 

try this

var element = document.getelementbyid("gender"); var gender = element.options[element.selectedindex].value; 

Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -