Jump to content

Get text value of option tag, NOT tag value


mem0ri

Recommended Posts

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.