mem0ri Posted March 13, 2008 Share Posted March 13, 2008 I have a page in which there is an option list that looks something like: <option value="527">3m</option> And I need to fill the text value (the 3m) to a hidden input tag like so: <input name="size" id="size" type="hidden" value="3m" /> So far...I've managed the following JavaScript code <SCRIPT type="text/javascript"> var selects = document.getElementsByTagName('option'); for(i=0; i < selects.length; i++) { if(selects[i].hasAttribute('selected')) document.getElementById('size').setAttribute('value', selects[i].innerText); } </SCRIPT> The problem line is: document.getElementById('size').setAttribute('value', selects[i].innerText); Help me out please? Quote Link to comment Share on other sites More sharing options...
nogray Posted March 13, 2008 Share Posted March 13, 2008 innerText is only IE use something like this document.getElementById('size').setAttribute('value', selects.options[selects.selectedIndex].text); Quote Link to comment Share on other sites More sharing options...
haku Posted March 14, 2008 Share Posted March 14, 2008 if that doesn't work, change .text to .data 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.