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

populate text box on change of combo box

Status
Not open for further replies.

richey1

Technical User
Oct 5, 2004
184
0
0
GB
Hi

I have a combo box on an asp form, which reads values from a sql database using a sub and a function in an include file as below

Code:
Sub getPestTypes(oRS)
	On Error Resume Next

	if Err.number=0 then
	set oRS = ExecQueryRS_X("CONN_Z","SELECT compTypeID, varIndicator,varCompType, varCost_Dom, varCost_Com FROM tblCompType where varIndicator='Pest'",null)

		if Err.Number <> 0 then
			set oRS = Nothing
		end if

	else
	end if
End Sub

Function getPestName(strID)
	Dim oRS
	
	set oRS = ExecQueryRS_X("CONN_Z","SELECT compTypeID, varIndicator,varCompType, varCost_Dom, varCost_Com FROM tblCompType WHERE compTypeID=?",Array(adnumeric,5,strID))
	if Err.number=0 then
		getPestName=oRS(0)
		oRS.Close
	else
		getPestName=""
	end if
	
	set oRS = Nothing
End Function

within the asp file i have this which allows the user to select either commercial or domestic and further below the code to build up the select for the pest types (using the sub above)
if the user selects, say Bee and Commercial I'd like to fire an onchange event for selPest and read the value from
varCost_Com from tblCompType (as specified in the sub) for example. if it was domestic then varCost_Dom

so an example row in tblCompType is

CompTypeID, varInidcator, varCompType, varCost_Dom, varCost_com
10, Pest, Bees, Do not treat, Do not treat

thanks
kim

Code:
	'Pest Types
	'===========
	set oRSPestTypes = Server.CreateObject("ADODB.Recordset")
	getPestTypes oRSPestTypes
	
	Response.Write "        <tr>" & vbLf
	'at the last minute, client requested that input box be labelled as 'Reason for Enquiry'
	'hence, the below label; in the database though, the table corresponding to this is still called  

'CTS_PEST TYPES'
	'inconsistent I know, but what can you do about last minute changes!?
	'so, if client uses Business Objects and asks which table to use for 'Reason for Enquiry', give above table name
	Response.Write "  <td align=right><span class=clsMainText>Pest Type:</span></td>" & vbLf
	Response.Write "<td><select name=selPest onchange=""selPestChange();frmEnquiry.submit()"">" & vbLf
	Response.Write "    <option value=""-1"">" & vbLf

 	oRSPestTypes.MoveFirst
	
	if	Err.Number = 0 then
		while not oRSPestTypes.EOF
			Response.Write "    <option " &  

IIf(Request("selPest")&""=CStr(oRSPestTypes("compTypeID")),"SELECTED","") & " value=""" & oRSPestTypes("compTypeID") & """>" 

&  Server.HTMLEncode(oRSPestTypes("varCompType")) & vbLf
			oRSPestTypes.MoveNext
		wend
	else
		Response.Write "<option value=""-1"">CANNOT GET LIST OF PEST TYPES??"
	end if

	Response.Write "</select>"
    Response.Write "          <span class=clsMainText>Pest Cost:</span><font size=1><span class=clsTextColor></span></font>" 

& vbLf
	Response.Write "            <input type=text readonly=true size=10 name=txtPestCost value=" & 

Server.HTMLEncode(Request("txtPestCost")&"") & ">" & vbLf
response.write " </td>" & vbLf
	oRSPestTypes.Close
	set oRSPestTypes = nothing
    Response.Write "        </tr>" & vbLf

Code:
    Response.Write "function selPestChange()" & vbLf
    Response.Write "{" & vbLf
????????
    Response.Write "    }" & vbLf
    Response.Write "}" & vbLf
 
I'd like to fire a [highlight]client-side[/highlight] event for a [highlight]client-side element[/highlight] and read the value from a [highlight]server-side[/highlight] variable.

 
[COLOR=black yellow]Yes - I understand that, but what you've given us is purely server-side. To give you client-side JS, we need the appropriate client-side code for the select element. This is the code the browser sees, and you can find it by viewing the source that is delivered to the browser.[/color]

You will also need to deliver all your server-side variables to the page if you need to access them client-side. Or, submit a form back to the server each time. You cannot arbitrarily call or access server-side code without doing one of the two (or using something like AJAX).

Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
[highlight]BRPS, wake up! that was Sheco![/highlight]

*cLFlaVA
----------------------------
[tt]I already made like infinity of those at scout camp...[/tt]
beware of active imagination: [URL unfurl="true"]http://www.coryarthus.com/[/url]

BillyRayPreachersSonIsTheLeetestHax0rDude
[banghead]
 
[highlight]lol[/highlight] [smile]


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
[highlight]Please don't shoot me![/highlight]

[machinegun] [rofl]
 
Doh! That'll teach me to read the posts a bit more carefully!

I'm having one of those days today, really. It's our very last day that our app is in testing, and I've had more defects returned to me as "unfixed" than you can image - to make matters worse, they aren't unfixed - and so have all been sent back...

[COLOR=black yellow]Wonder if this yellow thing will catch on?[/color]


[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Stop with the yellow, much to bright and it gives me a headache.

Christiaan Baes
Belgium

I just like this --> [Wiggle] [Wiggle]
 
I came up with the code below which is what i wanted..............my vote is a no for the yellow by the way !

thanks
kim

Code:
Response.Write "var arrTargets3 = new Array();" & vbLf

while not rsWebLink.eof
if CLng(rsWebLink("CompTypeID")) >= 0 then
Response.Write "arrTargets3[" & rsWebLink("CompTypeID") & "]='" & rsWebLink("varCost") & "';" & vbLf
end if
rsWebLink.MoveNext
wend

Response.Write "function selPestChange()" & vbLf
Response.Write "{" & vbLf
' set the Pest Cost
Response.Write "  document.frmEnquiry.txtPestCost.value=arrTargets3[document.frmEnquiry.selPest.value];" & vbLf
Response.Write "}" & vbLf
Response.Write "</script>" & vbLf
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top