javascript - JS: output inconsistencies -
This code receives the user input and takes it to the location of "selected", e.g. < P> 1 input
User input:
Apple process (what happens inside):
"Img2 /" + + Apple + ".jpg"; Output:
Apple.jpg (image) The problem once user inputs a query
orange process (what happens inside) is not compatible image code, outputs to the previous one
2 input user input:
Is): "img2 /" + + apple + ".jpg"; Output:
Apple.jpg (image) // wrong false var q = document.getElementById ("code"); If (q.selectedIndex & gt; 0) {var selected = q.options [q.selectedIndex] .value; Var src = "img2" "+ selected +" .jpg "; var img = document.getElementById (" placeholderIMG "); Img.src = src; Img.style.display =" inline ";} & lt; select name = "Code" id = "code" size = "" disabled = "true" hidden = "true" & gt; option value = "apple"> apple gt; & lt; Option value = "acne"> acetus gtc: // so far more and more How can I fix it?
returns its mistake within the line
if (q.select indices> gt; 0) selected index The property is 0 when the first row is selected ("apple" in your case). For this, if the statement only does something other than "Apple", then it will work. selectedIndex is the property -1 when no one is selected, then not ! Should be changed with the statement:
if (q.selectedIndex> 1)
Comments
Post a Comment