Solved

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

Posted on 2008-06-25
3
214 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

Question has a verified solution.

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

Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

726 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