Solved

How to auto fill an option tag based on a previous selection

Posted on 2008-06-25
3
198 Views
Last Modified: 2012-06-22
I am trying to setup a form as follows

User makes a selection from an option drop down that pulls the options from a database

I then want the next box to auto fill based on the selection from above

Both options are derived from a database

so as an example

User selects a state from a drop down
The next box has the State Abbreviation and I want that to be auto filled in based on the state name

How do I do this
0
Comment
Question by:ostashenp
  • 2
3 Comments
 
LVL 36

Accepted Solution

by:
SidFishes earned 250 total points
ID: 21867694
this shows you how it works

<cfoutput><cfset TempQry= querynew("")>
 
<cfset queryaddcolumn  (TempQry, "Col1", "CF_SQL_integer", ListToArray("1,2,3,4,5,6"))>
<cfset queryaddcolumn  (TempQry, "Col2", "cf_sql_varchar", ListToArray("here, there, everywhere, nowhere, anywhere,somewhere"))>
<select onChange="document.getElementById('stateName').value=this.value;">
<cfloop query="tempqry">
<option value="#tempqry.col1#">#tempqry.col2#</option>
</cfloop>
</select>

<select id="stateName">
<cfloop query="tempqry">
<option value="#tempqry.col1#">#tempqry.col2#</option>
</cfloop>
</select>

</cfoutput>


however do you really need to select a state and and fill another option with the abbreviation? unless there's a specific need why not just use the stateabbr as the option value and the statename as the option text

<option value="#tempqry.stateabbr#">#tempqry.statename#</option>





0
 
LVL 36

Expert Comment

by:SidFishes
ID: 21867704
btw..this bit

<cfset TempQry= querynew("")>
 
<cfset queryaddcolumn  (TempQry, "Col1", "CF_SQL_integer", ListToArray("1,2,3,4,5,6"))>
<cfset queryaddcolumn  (TempQry, "Col2", "cf_sql_varchar", ListToArray("here, there, everywhere, nowhere, anywhere,somewhere"))>

just creates a temp query for testing you'd replace that with your own query
0
 
LVL 39

Assisted Solution

by:gdemaria
gdemaria earned 250 total points
ID: 21867946
You have two select tags, the second should populate based on the selection of the first; true?  

Here is a coldfusion custom tag that does that for you...

http://www.geocities.com/thanny/CF_TwoSelectsRelated.zip
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

If I have to fix slow responding website my first thoughts are server side optimizations: the database may not be optimized or caching is not enabled, or things like that. We often overlook another major part of our web application: the client. We o…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now