rwrona
05-05-2004, 02:43 PM
Can anyone point me to a reference that I can use to populate the contents of an edit field or even a static text field based on a selection in a drop down menu? I have a list of codes people can choose from. Once they select the code and click the seach button, I want to display the explanatory text for them in a field on the same page.
Any help would be very much appreciated.
Thanks!
diades
05-05-2004, 03:47 PM
Hi rwrona
Welcome to the City!:)
To gather the selected value from a select you need to access the options collection and find, from that, which the user selected. To do that us:
object.options[object.selectedIndex].value
you can use this in the onchange event-handler for the select thus:
<select onchange="myText.value = this.options[this.selectedIndex].value">
<option value="a">A</option>
<option value="b">B</option>
<option value="c">C</option>
<option value="d">D</option>
</select>
<input name="mytext" type="text" />
javascript???
then,,, or like this maybe ??? If you want help to appear on the same page as the form.
<form>
<select name="whatever" onChange="document.getElementById('message').innerHTML=this.value;">
<option value="0">pick one</option>
<option value="you selected do this">Do This</option>
<option value="you selected do that">Do That</option>
</select>
</form>
<div id="message">
da Message
</div>
Note my JavaScript is not good. Daides is a much better bet :D
Coldfusion If you want help to appear on the same page as the search results
If you want to submit the form info to a processing page then display the help message on that then you could use a switch.
Say the select box name was "whatever" as above, and the values of the options were a, b, c etc. Then on the processing page you could test the value passed and display the appropriate text.
<cfswitch expression="#whatever#">
<cfcase value="a"><p>You picked A</p></cfcase>
<cfcase value="b"><p>You picked B</p></cfcase>
<cfcase value="c"><p>You picked C</p></cfcase>
</cfswitch>
Note using CFSWICH/CFCASE is a better option than CFIF CFELSEIF and CFELSE as the switch jumps out of the loop imediately it finds a match (thus saving a few serverside milliseconds) whereas CFIF etc will test all IF IFELSE statements before it continues
vBulletin® v3.6.4, Copyright ©2000-2008, Jelsoft Enterprises Ltd.