Jump to content

Select box text value


gerkintrigg

Recommended Posts

I am trying to work out how to get the text value of a drop down box. I am using the following code but it doesn't seem to work:

onchange="products_price.value=this.text;"

 

I just need to get the "visible" part of the select box and use it as a number variable to select a price (see it in action here: http://ww.magic2k.com/alcolim/ )

 

 

Link to comment
https://forums.phpfreaks.com/topic/148225-select-box-text-value/
Share on other sites

If you set an ID for the select element you can use:

 

onchange="document.getElementById('elements_id').value=this.text;"

 

If the form has a name:

 

onchange="documents.forms['form_name'].value=this.text;"

 

Or if you work out the form number:

 

onchange="document.forms[0].products_price.value=this.text;"

 

Remember though the form number starts from 0 and not 1!

 

Adam

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.