Home > Archive > ASP > July 2004 > ASP option box secondary value update other field?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
ASP option box secondary value update other field?
|
|
| WC Justice 2004-07-26, 8:55 pm |
| 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
| |
| Ray at 2004-07-27, 3:55 pm |
|
"WC Justice" <WCJEInc@bellsouth.net> wrote in message
news:DtfNc.44936$Yw3.7683@bignews3.bellsouth.net...
>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
| |
| WC Justice 2004-07-27, 3:55 pm |
| Thanks, I'll check it out.
"Ray at <%=sLocation%> [MVP]" <myfirstname at lane34 dot com> wrote in
message news:ORPDJK%23cEHA.1764@TK2MSFTNGP10.phx.gbl...
>
> "WC Justice" <WCJEInc@bellsouth.net> wrote in message
> news:DtfNc.44936$Yw3.7683@bignews3.bellsouth.net...
the[color=darkred]
>
> 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
>
>
| |
| WC Justice 2004-07-27, 3:55 pm |
| Thanks, I'll check it out.
"Ray at <%=sLocation%> [MVP]" <myfirstname at lane34 dot com> wrote in
message news:ORPDJK%23cEHA.1764@TK2MSFTNGP10.phx.gbl...
>
> "WC Justice" <WCJEInc@bellsouth.net> wrote in message
> news:DtfNc.44936$Yw3.7683@bignews3.bellsouth.net...
the[color=darkred]
>
> 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
>
>
|
|
|
|
|