Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting Text Value From Select 1

Status
Not open for further replies.

jl8789

MIS
May 22, 2003
293
US
Is there a way in cold fusion to get the display value from a select form control after the form has been submitted? Let's say sec_level is my select name. Of course, #FORM.sec_level# will give me the value of the option, but can I get the text display of that option without having to do any database look ups with the option value I have etc?
Like in JavaScript, var objValue = new String(obj.value); gives me the display value into the variable objValue. Can I do this with Cold Fusion?

THANKS!
 
Actually I need to get the display value of the selectedIndex of the control, not the value! I know it is weird, but I have 2 display text values that have the same option. We needed to add another display value with the same option value(because of other code that uses the value) and just do somehting slightly different somewhere else, if the display value is different... IS there a way?

Thanks!!
 
One way to approach this would be to have hidden form fields which will contain the value you wish to pass. The onsubmit event of the form can call some javascript which populates the hidden field with the text of the selected index in the select (as opposed to the value). Then on the action page read the value of the hidden form. Of course this wont work if Javascript is disabled so you need to take this into account
 
Ok, how do I get the text of the selectedIndex? I have tried, var vacGrp = document.empInfo.vac_grp[document.empInfo.vac_grp.selectedIndex]; And I get undefined. If I do var vacGrp = document.empInfo.vac_grp[document.empInfo.vac_grp.selectedIndex].value; Using the .value, I get the value, and if I try .text I get undefined.
 
you are missing the options collection.

i put it on 2 lines for readability

Code:
var sIndex = document.empInfo.vac_grp.selectedIndex;
var selected_text = document.empInfo.vac_grp.options[sIndex].text;


=========================================
I have not failed. I've just found 10,000 ways that won't work.
Thomas A. Edison
 
Is this what you're after?
Code:
<select name="sec_level">
  <option value="#MyValue#,#MyText#">#MyText#</option>
</select>

----Action Page-----

<cfoutput>
 Option Value = #ListFirst(Form.sec_level)#<br>
 Option Text = #ListLast(Form.sec_level)#<br>
</cfoutput>
Just put both values in the option tag, then treat it as a list and seperate them.


Hope This Helps!

ECAR
ECAR Technologies

"My work is a game, a very serious game." - M.C. Escher
 
I concur, Ecar's solution is more elegant and doesn't rely on javaScript being enabled
 
Thanks. Pigsie's solution is exactly what I need. Thank you NorthStarDA for supplying the exact code I needed!!!!! I could have used ECAR's solution if I was coding this form from the ground up, but there is much code already in place. That is also why I needed to keep 2 values the same in the select box, cuz essentially we want to treat them the same as far as their values go throughout the rest of the form. BUT, we want to do some slight additional code if one of the text values is different. THANKS!!!!!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top