Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can CFSELECT values be determined by the first cfselect in a form?

Status
Not open for further replies.

maverik59

Programmer
Oct 30, 2002
67
0
0
GB
Hi

I have a form of manufacturers and models, i want the models drop down menu to only show the models for the manufacturer which is selected. Does this make sense? I have tried using the cfqueryparam and referring it back to the form, but this is unsuccessful as on the first loading of the page.

Here is my code....hope someone might be able to help... <cfparam name=&quot;action&quot; default=&quot;&quot;>


<cfquery datasource=&quot;lvl&quot; name=&quot;cars&quot;>
Select * from dt_models
</cfquery>

<cfquery datasource=&quot;lvl&quot; name=&quot;manufacturers&quot;>
Select *
from dt_manufacturers
</cfquery>

<cfquery datasource=&quot;lvl&quot; name=&quot;modelq&quot;>
Select model_manufacturer,model_name from dt_models
where model_manufacturer = <cfqueryparam value=&quot;#form.manufacturer_id#&quot; cfsqltype=&quot;cf_sql_integer&quot;>
</cfquery>

<cfoutput>

<cfform action=&quot;delivery_action.cfm&quot; method=&quot;post&quot;>
<table>
<tr><td>Please enter vehicle details:</td></tr>
<!---Field Manufacturer --->
<tr><td>Manufacturer</td><td>
<cfselect query=&quot;manufacturers&quot; name=&quot;manufact&quot; display=&quot;manufacturer_name&quot; value=&quot;manufacturer_id&quot;></cfselect>
</td></tr>


<!--Field:Model-->
<tr><td>Model</td><td>
<cfselect query=&quot;modelq&quot; display=&quot;#model_name#&quot; value=&quot;#model_name#&quot; name=&quot;model&quot;> </cfselect></td></tr>

<input type=&quot;submit&quot; value=&quot;Save&quot; class=&quot;Submit&quot;>&nbsp;<input type=&quot;reset&quot; value=&quot;Reset&quot; class=&quot;submit&quot;>

</td></tr>
</td></tr>
</table>
</cfform>
</cfoutput>



 
<cfparam name=&quot;man_id&quot; default=&quot;&quot;>
<cfparam name=&quot;mod_id&quot; default=&quot;&quot;>

<cfif not isDefined(&quot;manufacturers&quot;>
<cfquery datasource=&quot;lvl&quot; name=&quot;manufacturers&quot;>
Select *
from dt_manufacturers
</cfquery>
</cfif>

<FORM name='Frm1' ACTION=&quot;thispage.cfm&quot; METHOD='GET'>
Manufacturer: <select name='man_id' onchange='document.Frm1.submit()'>
<cfoutput query='manufacturers'>
<option value=#manufactuer_id# <cfif #man_id# IS #manufacturer_id#>selected</cfif>>#manufacturer_name#</cfoutput>
</select>
</form>
<cfif man_id NEQ &quot;&quot;>
<cfquery datasource=&quot;lvl&quot; name=&quot;modelq&quot;>
Select model_manufacturer,model_name from dt_models
where model_manufacturer = #man_id#>
</cfquery>
<form name=&quot;Frm2&quot; ACTION=&quot;actionpage.cfm&quot; METHOD=&quot;POST&quot;>
Model: <select name='mod_id'>
<cfoutput query='modelq'>
<option value=#model_manufacturer#>#model_name#
cfoutput>
</cfif>

<input type=submit value=&quot;Submit&quot;>
</form>

Hope this helps.
mansii
 
Sorry, mistyped at some point:

<cfparam name=&quot;man_id&quot; default=&quot;&quot;>
<cfparam name=&quot;mod_id&quot; default=&quot;&quot;>

<cfif not isDefined(&quot;manufacturers&quot;)>
<cfquery datasource=&quot;lvl&quot; name=&quot;manufacturers&quot;>
Select *
from dt_manufacturer
</cfquery>
</cfif>

<FORM name='Frm1' ACTION=&quot;thispage.cfm&quot; METHOD='GET'>
Manufacturer: <select name='man_id' onchange='document.Frm1.submit()'>
<cfoutput query='manufacturers'>
<option value=#manufacturer_id# <cfif #man_id# IS #manufacturer_id#>selected</cfif>>#manufacturer_name#</cfoutput>
</select>
<input name=&quot;man_id&quot; type=&quot;Hidden&quot; value=#manufacturer_id#>
</form>
<cfif man_id NEQ &quot;&quot;>
<cfquery datasource=&quot;lvl&quot; name=&quot;modelq&quot;>
Select * from dt_models
where model_manufacturer = '#man_id#'
</cfquery>
<form name=&quot;Frm2&quot; ACTION=&quot;actionpage.cfm&quot; METHOD=&quot;POST&quot;>
Model: <select name='mod_id'>
<cfoutput query='modelq'>
<option value=#model_name#>#model_name#
</cfoutput>
</select>
<input name=&quot;manufact&quot; type=&quot;Hidden&quot; value=#man_id#>
<input name=&quot;model_1&quot; type=&quot;Hidden&quot; value=#model_name#>
</cfif>
<br>
<input type=submit value=&quot;Submit&quot;>
</form>

regards,
mansii
 
Many Thanks, there were a few problems at first but it works now! One thing when I select a manufacturer the model comes up fine except the manufacturer resorts back to the original on the display. How can i make it stay on the chosen manufactuer?

Many Thanks
 
simon,
I was having a vacation these two days. Have you solved your problem? If not, here's how I did the trick (I should have done this in the previous thread):

See the first line:
<cfparam name=&quot;man_id&quot; default=&quot;&quot;>
Add this line just below it:
<CFIF not IsDefined('url.man_id')>
<CFSET url.man_id = #man_id#>
</CFIF>

Hope this helps,
mansii
 
Yes i sorted this, i am having real trouble posting the manufacturer id into the database, i have set up a param variable and tried to pass it between forms but it doesn't want to know. I get the error message &quot; 'manufacturer_id' is undefined in 'form1.man_id'. I have tried variations but to no avail. I even tried having form 2 inside form 1 rather than 2 seperate forms....I knew then i was clutching at straws! Any ideas? I would copy and paste the code in but its a good 200 lines now. I really appreciate your help.
 
simon,
first, let's keep them in two forms. second, I wonder what the manufacturer_id's data type is: numeric or string? If numeric, make adjustment to the parameter default value, the hidden input value and the comparison statement of the first option.
Anyways, I'll see it tomorrow morning.
regards,
mansii
 
simon,
remove this line:
<input name=&quot;man_id&quot; type=&quot;Hidden&quot; value=#manufacturer_id#>
from the first form.
Give it a go.
 
Hi,

I have messed round with this to no avail. I don't know what i'm doing wrong am i not declaring a variable somewhere? The strange thing is man_id is passed as a variable correctly in the first form as it says it in the server variables debugging info. But when i click the submit button it just seems to disappear....

Many Thanks, how long have u been doing coldfusion for?


<cfparam name=&quot;action&quot; default=&quot;&quot;>
<cfparam name=&quot;id&quot; default=&quot;-1&quot;>
<cfparam name=&quot;man_id&quot; default=&quot;numeric&quot;>
<CFIF not IsDefined('url.man_id')>
<CFSET url.man_id = #man_id#>
</CFIF>

<cfquery datasource=&quot;lvl&quot; name=&quot;cars&quot;>
Select * from dt_models
</cfquery>

<cfquery datasource=&quot;lvl&quot; name=&quot;manufacturers&quot;>
Select *
from dt_manufacturers
</cfquery>

<!-- Edit Method -->
<cfquery datasource=&quot;lvl&quot; name=&quot;caredit&quot; maxrows =&quot;1&quot;>
Select * from dt_models,dt_manufacturers
Where dt_models.model_id=<cfqueryparam cfsqltype=&quot;CF_SQL_INTEGER&quot; value=&quot;#id#&quot;>
AND
dt_manufacturers.manufacturer_id=dt_models.model_manufacturer
</cfquery>


<cfform name=&quot;Form1&quot; action=&quot;delivery2.cfm&quot; method=&quot;get&quot;>
<table>
<tr><td><a href=&quot;/delivery_times.cfm&quot;>Search,Edit&Delete</a> <a href=&quot;/delivery_results.cfm&quot;>View Entire Vehicle Database</a></td></tr>
<tr><td>Please enter vehicle details:</td></tr>
<tr><td>Manufacturer: <select name=&quot;man_id&quot; onchange=&quot;document.Form1.submit()&quot;>
<cfoutput query=&quot;manufacturers&quot;>
<option value=&quot;#manufacturer_id#&quot;>#manufacturer_name#</option>
<cfif #man_id# EQ #manufacturer_id#>
<option value=&quot;#manufacturer_id#&quot; selected=&quot;#manufacturer_name#&quot;>#manufacturer_name#</option>
</cfif>
</cfoutput>
</select>
</tr></td>
</cfform>

<cfif man_id NEQ &quot;&quot;>
<cfquery datasource=&quot;lvl&quot; name=&quot;modelq&quot;>
Select * from dt_models
Where model_manufacturer = '#man_id#'
</cfquery>

<cfquery name=&quot;manuname&quot; datasource=&quot;lvl&quot;>
Select Distinct manufacturer_name from dt_models,dt_manufacturers
Where model_manufacturer=manufacturer_id
and dt_manufacturers.manufacturer_id='#man_id#'
</cfquery>


<cfform name=&quot;Form2&quot; action=&quot;delivery_action.cfm&quot; method=&quot;post&quot;>
<tr><td>Model: <select name=&quot;mod_id&quot;>
<cfoutput query=&quot;modelq&quot;>
<option value=&quot;#model_name#&quot;>#model_name#</option>
</cfoutput>
</select>
</td></tr>

<tr><td>
<input type=&quot;hidden&quot; name=&quot;man_id&quot; value=&quot;#man_id#&quot;>
<input type=&quot;hidden&quot; name=&quot;model_id&quot; value=&quot;#id#&quot;><cfif id EQ -1><input type=&quot;hidden&quot; name=&quot;action&quot; value=&quot;Add&quot;><cfelse><input type=&quot;hidden&quot; name=&quot;action&quot; value=&quot;Edit&quot;></cfif>
<input type=&quot;submit&quot; value=&quot;Save&quot; class=&quot;Submit&quot;>
</tr></td>
</table>
</cfform>
</cfif>
 
Magic - added this line at the end. Many thanks for your help. I would not have got this far otherwise! And i've just found out there is a custom tag available for this!!! aahh. It might be worth installing.

added this line at the bottom.

<input type=&quot;hidden&quot; name=&quot;man_id2&quot; value=&quot;<cfoutput>#man_id#</cfoutput>&quot;>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top