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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.