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? Link to comment https://forums.phpfreaks.com/topic/96006-get-text-value-of-option-tag-not-tag-value/ 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); Link to comment https://forums.phpfreaks.com/topic/96006-get-text-value-of-option-tag-not-tag-value/#findComment-491625 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 Link to comment https://forums.phpfreaks.com/topic/96006-get-text-value-of-option-tag-not-tag-value/#findComment-491904 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.