javascript - Accessing Selected Value from a Pulldown menu -


i having trouble in accessing selected value dropdown menu. when try access value selected in javascript function displayphoto, no value being accessed @ (i tried print out in textfield). doing wrong? thanks!

here html part:

<form id="colorchoice">     <img id="photo" src="red.jpg" alt="red" />     <select name="color" size=5>          <option value="red" onclick="jsfunction()">red</option>          <option value="blue" onclick="jsfunction()">blue</option>          ...     </select> </form> 

(i have tried 'onclick' , 'onchange', both doesn't work.)

here javascript part:

function jsfunction(){     var imagefile; = document.getelementbyid("colorchoice").color.value + ".jpg";     ... }   

you need put onchange on select element.

<form id="colorchoice">     <img id="photo" src="red.jpg" alt="red" />     <select name="color" id="color" size="5" onchange="jsfunction()">          <option value="red">red</option>          <option value="blue">blue</option>          ...     </select> </form> 

ther ; in function infront of imagefile

function jsfunction(){  var imagefile = document.getelementbyid('color').value + '.jpg';  alert(imagefile); }  

Comments