Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2004
    Posts
    2

    Unhappy Unanswered: getting the price from a selected name into a text box...

    I currently have all my names going into a selectbox..but i also want the price of the name selected to go into a text box...
    can anyone help me out with the code...

    This is what i have so far.....

    <%
    set conn=Server.CreateObject("ADODB.Connection")
    conn.Provider="Microsoft.Jet.OLEDB.4.0"
    conn.Open(Server.Mappath("dbTest.mdb"))

    set rs = Server.CreateObject("ADODB.recordset")
    rs.Open "SELECT Name FROM Cpu", conn
    %>



    <TABLE BORDER=0 FONT SIZE="2">
    <TR>
    <TD ALIGN=RIGHT><H5>Combo1:
    </TD>
    <TD> <SELECT name=selection>
    <OPTION value=selectzero selected>None
    <% do until rs.EOF
    for each x in rs.Fields
    Response.Write("<OPTION value=")
    Response.Write(x.value)
    Response.Write(">")
    Response.Write(x.value)
    next
    rs.MoveNext
    loop
    Response.Write("</OPTION></SELECT>")

    rs.close
    conn.close
    %>
    </TD>
    <TD>
    $<input type="text" name="amount" value="0" SIZE=4 readonly="readonly">
    </TD>
    </TR>

  2. #2
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    Do you want the value in the text box to change dynamically or do you want to submit the form back to get the value?

    If you want it dynamically you will need to write some client side script, either vbscript or JavaScript.

    If you want to submit back, then you need to determine what value was selected, get the price for that value and response.write it back to the input box.

  3. #3
    Join Date
    Feb 2004
    Posts
    2
    I want it to happen dynamically....

    jsSetText() {
    Textbox.text = selection.SelectedValue.ToString()
    }

    <TD> <SELECT name=selection OnChange:"jsSetText()">
    <OPTION value=selectedzero selected>None
    <% do until rs.EOF
    for each x in rs.Fields

    i'm sure it looks something like this but i'm a little confused how it will get the price from the corresponding name with out a sql statement...and if that is needed where do i set that...

  4. #4
    Join Date
    Jun 2003
    Location
    USA
    Posts
    1,032
    Here is something from my Invoice Detail page on my Web database at www.bullschmidt.com/login.asp.

    It calls a few of my library functions but hopefully even without thoses specific details this might give you some JavaScript ideas about it.

    <script type="text/javascript"> <!--
    function jsRecalcPg() {
    // Dim var.
    var frm;
    var strInvDetailProdDescr;
    var varInvDetailProdPrice;
    var varInvDetailQty;
    var varInvDetailTotal;

    // Form.
    frm = document.frmMain;

    // InvDetailProdDescr.
    // Retrieve from combo.
    strInvDetailProdDescr = frm.InvDetailProdID.options[frm.InvDetailProdID.selectedIndex].text;
    // Truncate to just the desired col.
    strInvDetailProdDescr = strInvDetailProdDescr.substring(21, 41);
    // Trim.
    strInvDetailProdDescr = jpsjsTrim(strInvDetailProdDescr);
    // Set form fld.
    frm.InvDetailProdDescr.value = strInvDetailProdDescr;

    // InvDetailProdPrice.
    // Retrieve from combo.
    varInvDetailProdPrice = frm.InvDetailProdID.options[frm.InvDetailProdID.selectedIndex].text;
    // Truncate to just the desired col.
    varInvDetailProdPrice = varInvDetailProdPrice.substring(42, 52);
    // Trim.
    varInvDetailProdPrice = jpsjsTrim(varInvDetailProdPrice);
    // Set form fld.
    frm.InvDetailProdPrice.value = varInvDetailProdPrice;

    // InvDetailTotal.
    // Convert to nums.
    varInvDetailProdPrice = jpsjsCNum(varInvDetailProdPrice);
    varInvDetailQty = jpsjsCNum(frm.InvDetailQty.value);
    // Multiply & round.
    varInvDetailTotal = jpsjsRound(varInvDetailProdPrice * varInvDetailQty, 2);
    // Format.
    varInvDetailTotal = jpsjsFormat(varInvDetailTotal, "type:number;pattern:$,0.00;neg)");
    // Set form fld.
    frm.InvDetailTotal.value = varInvDetailTotal;
    }
    //-->
    </script>
    J. Paul Schmidt, Freelance Web and Database Developer
    www.Bullschmidt.com
    Access Database Sample, Web Database Sample, ASP Design Tips

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •