0

I created an HTML5 Form with many <select> tags and I wanted to obtain some of the values or options in my JavaScript code.

I want to use the options the user created and use them in my JavaScript code. For example one select tag has many years in it and if the user selects a year below 2018. Then it alerts Welcome. How can I do it. My codes are below: Help me solve and see if there's a mistake. HTML CODE (Some are ignored) <select name="dropdown"> <option class="miyear" value="select">2015</option> <option class="miyear" value="select">2016</option> <option class="miyear" value="select">2017</option> <option class="miyear" value="select">2018</option> <option class="miyear" value="select">2019</option> </select> JS CODE: var yearofjoin=document.getElementsByClassName ("miyear"); var currentyear=getFullYear (); var difference; difference=currentyear-yearofjoin.value; alert ("Welcome"+difference);

19th Jun 2020, 10:47 AM
BTarget7
1 Respuesta
+ 1
put class at select instead of option and getElementsByClassName returns a HTMLCollection, so use [0]
19th Jun 2020, 12:29 PM
Gordon
Gordon - avatar