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 Chris Miller 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 initial values in my select box.

What am I doing wrong?

Thanks in advance for any help you can provide.


Soho34




 
Try this:

Code:
<script>
var final_vendors2="";
</script>
<cfset count=1>
    
    
    <cfoutput query="getServiceVendors">
    <cfloop query="getServiceVendors">
                <script>
                var final_vendors2+="<option value='#vendorid#'>#name#</option>";
                </script>
                <cfset count=count+1>
                
    </cfloop>
    </cfoutput>

<script>
document.getElementById('vendorname').innerHTML = final_vendors2;
</script>

Make sure the CF's right....the js should be.

Rick

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top