Save selection of a drop down box in a variable

I have a drop down list box that get populated from a database.  I want to save the #idumodel# field to a variable.  If the users changes there selection I also need it to update the variable with the new number.  Below is the code I use to populate the list box.

                                     <label>
                                     <select name="lmodel" required="yes">
                                     <option>Select Model</option>
                                     <cfoutput query="qmodel">
                                     <option value="#idumodel#">#model#</option>
                                     </cfoutput>
                                     </select>
                                     </label>
sonicimpulseAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SidFishesCommented:
to do that you need to reload the page to set the variable after the select onChange event happens

if you have other values on the page that could exist you would have to set url string variables for them as well

You could also do this using ajax but it's a bit more involved

<cfparam name="url.idumodel" default="">
 
<cfif url.idumodel neq "">
<cfset session.idumodel = url.idumodel>
</cfif> 
 
<label>
<select name="lmodel" required="yes"  onChange="window.open(this.options[this.selectedIndex].value,'_self')">
<option>Select Manufacturer</option>
<cfoutput query="qmodel">
thispage.cfm?idumodel=#qmodel.idumodel#.html" 
<cfif qmodel.idumodel. eq url.idumodel>selected</cfif>>#model#
<option value="#idumodel#">#model#</option>
</cfoutput>
</select>
</label>

Open in new window

0
SidFishesCommented:
oops sorry paste error


<cfparam name="url.idumodel" default="">
 
<cfif url.idumodel neq "">
<cfset session.idumodel = url.idumodel>
</cfif> 
 
<label>
<select name="lmodel" required="yes"  onChange="window.open(this.options[this.selectedIndex].value,'_self')">
<option>Select Manufacturer</option>
<cfoutput query="qmodel">
 
 
<option value="thispage.cfm?idumodel=#qmodel.idumodel#.html"
		<cfif qmodel.idumodel. eq url.idumodel>selected</cfif>>
		#model#
</option>
</cfoutput>
</select>
</label>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sonicimpulseAuthor Commented:
I'm assuming that I'm supposed to setup my query on the second page as follows

<cfquery name="listallused" datasource="users">
SELECT *
FROM vehicles
WHERE  model="#url.idumodel#">
</cfquery>

If this is correct its not working.  Can you please tell me the correct way
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

SidFishesCommented:
you didn't say you were doing a db update... or moving to a second page

what the code does is reload a single page and set a variable (or update it)

however, since session variables persists over pages, you can use the variable

session.idumodel on subsequent pages

ie:

WHERE  model="#session.idumodel#">

0
sonicimpulseAuthor Commented:
Here is the error I'm getting now.

Element IDUMODEL is undefined in SESSION.  
 
 
The error occurred in C:\ColdFusion8\wwwroot\automotive\upricelisting.cfm: line 43
 
41 : SELECT *
42 : FROM vehicles
43 : WHERE  model="#session.idumodel#">
44 : </cfquery>
45 :
 
0
incapitalCommented:
It looks like you have a superfluous > in your query.
0
sonicimpulseAuthor Commented:
I fixed that.  I even tried getting rid of the query and just doing a cfoutput of the variable to see if there was anything there and I still get the same error.
0
SidFishesCommented:
do you have sessionmanagement turned on in cfapplication?

<cfapplication  sessiontimeout="20" name="YourApp" sessionManagement="true">
0
sonicimpulseAuthor Commented:
I created a file called application.cfm and put the following line of code in it

<cfapplication  sessiontimeout="20" name="YourApp" sessionManagement="true">

I still get the same error
0
SidFishesCommented:
the code i posted works.. I use it all the time... since i don't know what you are doing with it before or after ..without more code it's impossible to diagnose...
0
sonicimpulseAuthor Commented:
I'm using this code that you gave me above on the first page.

The second page only has <cfoutput>#session.idumodel#</cfoutput>
<cfparam name="url.idumodel" default="">
 
<cfif url.idumodel neq "">
<cfset session.idumodel = url.idumodel>
</cfif> 
 
<label>
<select name="lmodel" required="yes"  onChange="window.open(this.options[this.selectedIndex].value,'_self')">
<option>Select Manufacturer</option>
<cfoutput query="qmodel">
 
 
<option value="thispage.cfm?idumodel=#qmodel.idumodel#.html"
                <cfif qmodel.idumodel. eq url.idumodel>selected</cfif>>
                #model#
</option>
</cfoutput>
</select>
</label>

Open in new window

0
sonicimpulseAuthor Commented:
Is the location of the cfset in the wrong place.  It would need to change every time the user clicks on the drop down box
0
SidFishesCommented:
it's in the right place

add this to the page

<cfdump var="#session#">

and post the results

also..how are you getting to the second page
0
sonicimpulseAuthor Commented:
I put that cfdump on both pages and here is the results

cfid         6301
cftoken       60069496
sessionid       YOURAPP_6301_60069496
urltoken       CFID=6301&CFTOKEN=600

Here is how i'm getting to the second page.  I took your code from above and replaced the "thispage.cfm" to the correct page "umodellisting.cfm"

0
SidFishesCommented:
ok well that's the problem...

you have to replace thispage.cfm with the name of the page that the code is on...otherwise doesn't reload and the variable never gets set..

0
sonicimpulseAuthor Commented:
ok couple of things and this is almost working the way I want.  If you want me to start a new help for this question just say so.  

When the pages reloads to set the session variable is clears the form.  I would like what ever the user picks in the drop down boxes to stay.

The second issue is when it saves the session variable it saves it as 60.htm or what ever the correct number is.
0
SidFishesCommented:
actually both issues should be fixed by fixing this typo
                                                                                                 ***
<option value="thispage.cfm?idumodel=#qmodel.idumodel#.html" <cfif qmodel.idumodel eq url.idumodel>selected</cfif>>

should be

<option value="thispage.cfm?idumodel=#qmodel.idumodel#"
                <cfif qmodel.idumodel eq url.idumodel>selected</cfif>>
0
sonicimpulseAuthor Commented:
Ok this is my code below.  Its saving the variable correctly but whats happening is its not displaying the values the user chose in the drop down boxes.  Its going back to the default.  This is all on the first page not the second page that the link goes to.  
0
sonicimpulseAuthor Commented:
I also noticed one other issue.  Its updating the variable but its always one behind.  So lets say my second selection was a honda accord and my third selection was a audi a4.  The variable should read audi a4 id but its reading the honda accord id.
0
sonicimpulseAuthor Commented:
All I'm trying to do is get these drop down boxes to work and store the selection of the second box in a variable.  Can someone please help me with this.
0
SidFishesCommented:
the code I provided does exactly what you asked ... you didn't mention multiple selects. You can't expect us to know what you want to do if you don't post complete code and/or let us know from the outset that the code you post is not all you want.

0
sonicimpulseAuthor Commented:
Thanks sorry for the misconfusion
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ColdFusion Language

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.