Solved

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

Posted on 2008-06-25
3
211 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.
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.

680 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