Jump to content
Sign in to follow this  
vchris

Get option text

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?

Share this post


Link to post
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?

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...
Sign in to follow this  

×
×
  • Create New...