[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2008-06-25
3
Medium Priority
?
221 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 1000 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 1000 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
The first step to building an amazing About page is to figure out what you want the page to say about your company. You then must grab the attention of the reader, boast a bit, tell a story and let others brag about you. With a little bit of thought…
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.
Suggested Courses
Course of the Month19 days, 3 hours left to enroll

834 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