ASP option box secondary value update other field?

W

WC Justice

I am building a site using ASP and some javascript (to make data entry
easier). I use ASP to create a recordset consisting of ProjectID,
ProjectName, and ProjectMileageRate, and the option box is built from the
recordset. I would like for the txtBillingItemMileageRate field on the form
to be populated with the ProjectMileageRate based on the ProjectID selected
in the combo box. I have experimented enough to see that I can mix ASP and
Javascript as in the following (it is currently triggered by a hyperlink for
experimentation purposes):

function jsUpdateMileageRate() {
document.frmBillingEntries.txtBillingItemMileageRate.value =
<%=rsUserProjects("ProjectMileageRate")%> ;

}

This function works fine, except that it is simply taking the first
ProjectMileageRate of the recordset.

The following is the code used to create the recordset and option box.

<td width="25%"><font size="2"><select size="1" name="optProject"
onBlur="javascript:jsUpdateTotals()" style="text-align: left; float: left;
font: 10">
<%
SET conn = server.createobject ("adodb.connection")
conn.open "DSN=" & Session("DSN")

SET rsUserProjects = Server.CreateObject("ADODB.Recordset")
rsUserProjects.CursorLocation = 3

strSQL = "SELECT tblUserProjectAuthority.UserID, tblProjects.ProjectName,
tblProjects.ProjectMileageRate," _
& "tblUserProjectAuthority.ProjectID,
tblUserProjectAuthority.UserProjectActive " _
& "FROM tblProjects INNER JOIN tblUserProjectAuthority ON " _
& "tblProjects.ProjectID = tblUserProjectAuthority.ProjectID " _
& "WHERE (((tblUserProjectAuthority.UserID)='" & Session("UserID") & "') AND
" _
& "((tblUserProjectAuthority.UserProjectActive)=True));"

rsUserProjects.open strSQL,conn

do until rsUserProjects.EOF
%>
<option
<%=rsUserProjects("ProjectID")%>><%=rsUserProjects("ProjectName")%></option>
<%
rsUserProjects.MOVENEXT
LOOP
%>
</select></font></td>
</tr>

<%
rsUserProjects.CLOSE
SET rsUserProjects = NOTHING
%>

Is there a way to populate the txtBillingItemMileageRate field with the
mileage rate associated with the selected Project? If so, please advise.

Also, I would appreciate any constructive criticism of the existing code.

Thanks
 
R

Ray at

WC Justice said:
I am building a site using ASP and some javascript (to make data entry
easier). I use ASP to create a recordset consisting of ProjectID,
ProjectName, and ProjectMileageRate, and the option box is built from the
recordset. I would like for the txtBillingItemMileageRate field on the
form
to be populated with the ProjectMileageRate based on the ProjectID
selected
in the combo box. I have experimented enough to see that I can mix ASP
and
Javascript as in the following (it is currently triggered by a hyperlink
for
experimentation purposes):

function jsUpdateMileageRate() {
document.frmBillingEntries.txtBillingItemMileageRate.value =
<%=rsUserProjects("ProjectMileageRate")%> ;

}

This function works fine, except that it is simply taking the first
ProjectMileageRate of the recordset.

This is the be expected, because remember, ASP runs on the server and then
delivers the result to the browser. The recordset object that you're
creating exists in the server's memory, and the javascript function runs in
the browser.

You will either have to dump your recordset values into a javascript array
so that the browser can see those values, or you will have to re-hit the
server to get the new updated value.

See here for some options: http://www.aspfaq.com/show.asp?id=2270

Ray at work
 
W

WC Justice

Thanks, I'll check it out.
Ray at said:
This is the be expected, because remember, ASP runs on the server and then
delivers the result to the browser. The recordset object that you're
creating exists in the server's memory, and the javascript function runs in
the browser.

You will either have to dump your recordset values into a javascript array
so that the browser can see those values, or you will have to re-hit the
server to get the new updated value.

See here for some options: http://www.aspfaq.com/show.asp?id=2270

Ray at work
 
W

WC Justice

Thanks, I'll check it out.
Ray at said:
This is the be expected, because remember, ASP runs on the server and then
delivers the result to the browser. The recordset object that you're
creating exists in the server's memory, and the javascript function runs in
the browser.

You will either have to dump your recordset values into a javascript array
so that the browser can see those values, or you will have to re-hit the
server to get the new updated value.

See here for some options: http://www.aspfaq.com/show.asp?id=2270

Ray at work
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top