ASP option box secondary value update other field?

Discussion in 'ASP General' started by WC Justice, Jul 26, 2004.

  1. WC Justice

    WC Justice Guest

    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
     
    WC Justice, Jul 26, 2004
    #1
    1. Advertising

  2. WC Justice

    Ray at Guest

    "WC Justice" <> wrote in message
    news:DtfNc.44936$...
    >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
     
    Ray at, Jul 27, 2004
    #2
    1. Advertising

  3. WC Justice

    WC Justice Guest

    Thanks, I'll check it out.
    "Ray at <%=sLocation%> [MVP]" <myfirstname at lane34 dot com> wrote in
    message news:ORPDJK%...
    >
    > "WC Justice" <> wrote in message
    > news:DtfNc.44936$...
    > >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, Jul 27, 2004
    #3
  4. WC Justice

    WC Justice Guest

    Thanks, I'll check it out.
    "Ray at <%=sLocation%> [MVP]" <myfirstname at lane34 dot com> wrote in
    message news:ORPDJK%...
    >
    > "WC Justice" <> wrote in message
    > news:DtfNc.44936$...
    > >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, Jul 27, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. AAJ
    Replies:
    0
    Views:
    641
  2. Mark Kolber
    Replies:
    4
    Views:
    366
  3. Replies:
    6
    Views:
    222
  4. VUNETdotUS
    Replies:
    25
    Views:
    514
    Thomas 'PointedEars' Lahn
    Nov 10, 2007
  5. jr
    Replies:
    3
    Views:
    493
Loading...

Share This Page