+ 3

How can I set the default value for an option in <select>?

How can I set the default value for an option in <select> when i select one option from first drop down selection then that collection of selected option bring to second drop down selection.i want to show one default option. https://code.sololearn.com/WgPRxFwWApe8/?ref=app

25th Jun 2018, 4:05 PM
M E
M E - avatar
6 Answers
+ 2
thanks alot for your suggestion,i hope this method works🙏
28th Jun 2018, 5:59 PM
M E
M E - avatar
25th Jun 2018, 4:30 PM
Ulisses Cruz
Ulisses Cruz - avatar
+ 1
Oh sorry I didn't understand exactly what you meant. You can use Javascript to add the 'selected' attribute to an option of the 2nd dropdown after the user has clicked on the 1st one like this: document.getElementByID("opt1").selected = "true"; This will work only if the option you want to mark as default has an id of 'opt1'. I have never tried it before, but I suppose it will work. Update: I saw your code and it is very interesting. Good luck with fixing it!
28th Jun 2018, 3:37 PM
giannismach
giannismach - avatar
+ 1
M E(biologist) You 're welcome!
28th Jun 2018, 7:00 PM
giannismach
giannismach - avatar
0
You can add the 'selected' attribute to the option you want to make default. This way, the option will be preselected.
28th Jun 2018, 12:14 PM
giannismach
giannismach - avatar
0
when i click to option in first drop down selection i want to show default option in second drop down selection but this way that you say dont work.
28th Jun 2018, 1:33 PM
M E
M E - avatar