lilman Posted May 31, 2007 Share Posted May 31, 2007 I have this code: <select size="1" name="sale" onChange="actionOrSelective();"> <option>Select</option> <option>Auction</option> <option>Selective</option> </select> Now I am trying to figure out how I can identify the value they selected. So here is my other code: var object = document.getElementById('sale').selected; That doesn't work. I was wondering if someone would help me out. Thank you Quote Link to comment Share on other sites More sharing options...
brissy_matty Posted June 1, 2007 Share Posted June 1, 2007 Try: var cinemaCode = document.getElementById('sale').value; Works for me - maybe not the best way but meh! Quote Link to comment Share on other sites More sharing options...
thedarkwinter Posted June 1, 2007 Share Posted June 1, 2007 Hi i'm no java-pro but i think you might find it a good idea to use the value tag in the options, so <select size="1" name="sale" onChange="actionOrSelective();"> <option value="">Select</option> <option value="auction">Auction</option> <option value="selective">Selective</option> </select> and then use either your way or mybe lilman's way of getting the value?? cheers, tdw Quote Link to comment Share on other sites More sharing options...
obsidian Posted June 1, 2007 Share Posted June 1, 2007 The comment above is accurate as far as needing the values within the options themselves. Otherwise, you'll need to access the elements with innerHTML, but that's another issue ... To figure out which one is selected, you need to use selectedIndex of the select box: function actionOrSelective() { var ele = document.getElementById('sale'); var obj = ele.options[ele.selectedIndex]; alert(obj.value); alert(obj.innerHTML); } Have fun with that. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.