0

Can't find the issue, select 2 isn't corresponding with Select 1

<!DOCTYPE html> <html lang="en"> <head> <script type="text/javascritp"> function populate(s1,s2){ var s1 = document.getElementById(s1); var s2 = document.getElementById(s2); s2.innerHTML = ""; if(s1.value == "Chevy"){var optionArray = ["|","camaro|Camaro"];} else if(s1.value == "Dogde"){var optionArray = ["|","avanger|Avanger"];} else if(s1.value == "Ford"){var optionArray = ["|","mustang|Mustang"];} for(var option in optionArray){var pair = optionArray[option].split("|"); var newOption = document.createElement("option"); newoption.value = pair[0]; newoption.innerHTML = pair[1]; s2.options.add(newoption); }</script> </head> <body> <h2>Choose Your Car</h2> Choose Make: <select id="slct1" name="slct1" onchange="populate(this.id,"slct2")"> <option value=""></option> <option value="Chevy">Chevy</option> <option value="Dogde">Dogde</option> <option value="Ford">Ford</option> </select> Choose Car Model: <select id="slct2"

4th Mar 2019, 4:39 PM
Clinton Itotoh
Clinton Itotoh - avatar
2 Respuestas
+ 1
At w3schools there is an example with selects and cars... :) take a look: https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_select_options3 (Is the last example in "Select options Collection" section)
5th Mar 2019, 1:53 AM
unChabon
unChabon - avatar
+ 1
Thanks Diego
5th Mar 2019, 8:44 AM
Clinton Itotoh
Clinton Itotoh - avatar