Jump to content

Get option text


vchris
 Share

Recommended Posts

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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:

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...