Help - Search - Members - Calendar
Full Version: Get option text
W3Schools Forum > Server Scripting > ColdFusion
vchris
Is there a way to get the option text instead of the value.

<option value="value">text</option>

I need to get that text. Is there a certain function for this?
Skemcin
in what respect do you need that text? On an action page?

Do you need both the value and teh text when the form is posted?

Is the value not in a database that you could look up.

Could you do this:
<option value="value,text">text</option>

and then parse the value on the action page using cfloop indexing by the comma?
vchris
I resolved this by simply creating a query to get the text.

The problem was that the value which is numeric 1,2,3... is not necessary for what I wanted to do but I couldn't change it. I needed the text to indicate to the user what was chosen. I thought by getting the text instead of querying it would be easier on the server but if there is no other way.
jesh
If you are using javascript on the client-side, you might try a hidden input that stores the text of the selected item and populate that data using java script:
CODE
<select id="myselect" onchange="updateHidden(this);">
  <option value="-1">Select an Option</option>
  <option value="1">Value 1</option>
  <option value="2">Value 2</option>
  <option value="3">Value 3</option>
</select>

<input type="hidden" id="h_myselect" value="-1" />

<script type="text/javascript">
function updateHidden(obj)
{
    var theText = obj.options[obj.selectedIndex].text;
    document.getElementById("h_myselect").value = theText;
}
</script>


But, as you well know, I don't know anything about CF nor whether it is possible to integrate javascript with it like this. Maybe it'll help.
vchris
I appreciate your input but unfortunately I cannot use javascript for what I am trying to do. I have standards I need to respect. It can only be CF. Thanks anyway.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.