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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help On Updating Select Box Entries???????

Status
Not open for further replies.

soho34

IS-IT--Management
Dec 28, 2004
102
US
Hi,

I have two select boxes that have the id attribute associated with them.

Code:
<cfoutput>
<form action="" id="serviceview" name="serviceview" method="post">
<select id="servicetype" name="servicetype" onchange="setVendors(this.value);">
			<cfloop query="gettypes">
				<option onchange="" value="#gettypes.servicetypesid#" <cfif #gettypes.servicetypesid# eq #oneservice.servicetypeid#>selected</cfif>>
					#gettypes.description#
				</option>
			</cfloop>
</select>

<select id="vendorname" name="vendorname">
			<cfloop query="getvendors">
				<option value="#getvendors.vendorid#" <cfif #getvendors.vendorid# eq #oneservice.vendorid#>selected</cfif>>
					 #getvendors.name#
				</option>
			</cfloop>
</select>
</form>

</cfoutput>

When my page is first called, they have pre-selected data are the select boxes already have options.

The second select box is dependent on the first.

When the first box is changed, a javascript function is invoked and another template to process a value is called.

function setVendors(servicetypeid){


<cfoutput>
backstage.location.href="bs_loadvendors.cfm?servicetypeid=" + servicetypeid;
</cfoutput>
}




Here's my logic from the (.cfm) file in case you need it.

Code:
<body>
<cfparam name="url.servicetypeid" default="0">

<!--- Update status window. --->
<cfoutput>
	<p>Servicetypeid supplied: &lsquo;#url.servicetypeid#&rsquo; (#val(url.servicetypeid)#)</p>
</cfoutput>
	
<cfif val(url.servicetypeid)>
	<cfquery name="getServiceVendors" datasource="#request.dsn#">
		SELECT	
			st.servicetypesid,
			vt.vendorid,
			v.name
		FROM 
			servicetypes st left join vendortypes vt
				on st.servicetypesid = vt.servicetypeid left join
				vendors v on vt.vendorid = v.vendorid
		WHERE 	
			st.servicetypesid = #url.servicetypeid#
	</cfquery> 


<cfset count=1>
	
	
	<cfoutput query="getServiceVendors">
	<cfloop query="getServiceVendors">
				<script>
				parent.serviceview.vendorname.options[#count#].text = "#name#";
				parent.serviceview.vendorname.options[#count#].value = "#vendorid#";
				</script>
				<cfset count=count+1>
				
	</cfloop>
	</cfoutput>
</body>


This processing holds the values that I want fed back into my second select box. Since the second select box already has values, I want those overwritten and replaced with my new values from this page.

The above is as far as I got. I’m able to see the new value pre-select after the first select box is changed, but there are still the intial values in my select box.

What am I doing wrong?

Thanks in advance for any help you can provide.


Soho34




 
This question has been asked a lot (I suppose I should write a FAQ). Your best bet is to use the custom tag CF_TwoSelectsRelated. It generates all of the data and JS without any of the associated pain trying to figure this out by yourself.

Look it up on the Dev Exchange on macromedia.com. It's worth it, believe me.

HTH,

Phil Hegedusich
Senior Programmer/Analyst
IIMAK
-----------
I'm not as think as you confused I am.
-----------
Flabbergasted (a.): Amazed at how much weight one has gained.
-----------
Oyster (n.): One who sprinkles their conversation with Yiddish expressions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top