Populate select field and textbox dynamically - no refresh

Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default Populate select field and textbox dynamically - no refresh

    Ive got a db table with the fields Product_Name and Product_Price.

    I want to display a pulldown containing the product names and display the
    price of the selected product in a text box.
    Currently, I can do the pulldown but to populate the price text box, I have
    to refresh the page.

    How can I pull all the data in, store it somehow, and have the price textbox
    reflect the selected product in the pulldown without reloading the page?

    Thanks!


    Targa Guest

  2. Similar Questions and Discussions

    1. How to build populate datagrids dynamically
      The data returned from the server in my flex app is one-dimensional: A 1 xyz A 2 abc A 3 pqr I want to put this data into a datagrid so...
    2. Dynamically Populate Multiple Select Boxes
      I am trying to develop an application where a user selects the Year, Make and Model of their vehicle. In the past, I had a query that input the...
    3. How do I dynamically bind a textbox into a grid field in ASP.NET using only the code behind?
      I am trying to take dynamically generated datagrid that is bound to a data source and make one of the fields on the grid into an editable textbox...
    4. Best way to populate a <SELECT>
      Hi All I've being doing it my own little way for sometime now, but I'm not sure if its the best. When I'm doing a recordset for a simple...
    5. Dynamically populate a word document from Oracle
      you may want to try posting in the JRun forums. There are a lot of very good JSP coders there. -- Mike ------------------- Michael Langner...
  3. #2

    Default Re: Populate select field and textbox dynamically - no refresh

    "Targa" <targa1SPAMSUCKS@alltel.net> wrote in message
    news:ObqhmIcREHA.1448@TK2MSFTNGP11.phx.gbl...
    > Ive got a db table with the fields Product_Name and Product_Price.
    >
    > I want to display a pulldown containing the product names and display the
    > price of the selected product in a text box.
    > Currently, I can do the pulldown but to populate the price text box, I
    have
    > to refresh the page.
    >
    > How can I pull all the data in, store it somehow, and have the price
    textbox
    > reflect the selected product in the pulldown without reloading the page?
    >
    > Thanks!

    Here's one approach that displays the product description and price
    together; watch for word-wrap.

    <% @Language="VBScript" %>
    <% Option Explicit
    '*
    '* Declare Constants
    '*
    Const cASP = "products.asp"
    Const cDSN = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ="
    Const cMDB = "products.mdb"
    '*
    '* Declare Variables
    '*
    Dim arrPRD(999,2)
    arrPRD(0,1) = 0 '* length of longest "product_desc"
    arrPRD(0,2) = 0 '* length of longest "product_price"
    Dim intPRD
    intPRD = 0
    Dim strPRD
    Dim intRST
    intRST = 0
    Dim strSEL
    Dim strSQL
    strSQL = "SELECT * FROM product ORDER BY product_desc"
    '*
    '* Declare Objects
    '*
    Dim objADO
    Set objADO = Server.CreateObject("ADODB.Connection")
    objADO.Open cDSN & Server.MapPath(cMDB)
    Dim objRST
    Set objRST = objADO.Execute(strSQL)
    '*
    '* Read "product" table
    '*
    While Not objRST.EOF
    intRST = intRST + 1
    intPRD = intPRD + 1
    arrPRD(intPRD,0) = objRST("product_code")
    arrPRD(intPRD,1) = objRST("product_desc")
    arrPRD(intPRD,2) = FormatNumber(objRST("product_price"),2)
    objRST.MoveNext
    Wend
    '*
    '* Destroy Objects
    '*
    Set objRST = Nothing
    Set objADO = Nothing
    '*
    '* Build "<select>"
    '*
    If intPRD > 0 Then
    For intPRD = 1 To intRST
    If arrPRD(0,1) < Len(arrPRD(intPRD,1)) Then
    arrPRD(0,1) = Len(arrPRD(intPRD,1))
    End If
    If arrPRD(0,2) < Len(arrPRD(intPRD,2)) Then
    arrPRD(0,2) = Len(arrPRD(intPRD,2))
    End If
    Next
    '*
    strSEL = "<select name='prod' style='font-family:Courier'>" & vbCrLf
    For intPRD = 1 To intRST
    strPRD = arrPRD(intPRD,1) & " .."
    strPRD = strPRD & String(arrPRD(0,1) -
    Len(arrPRD(intPRD,1)),".")
    strPRD = strPRD & String(arrPRD(0,2) -
    Len(arrPRD(intPRD,2)),".")
    strPRD = strPRD & " $ " & arrPRD(intPRD,2)
    strSEL = strSEL & "<option value ='" & arrPRD(intPRD,0) & "'>"
    strSEL = strSEL & strPRD & vbCrLf
    Next
    strSEL = strSEL & "</select>" & vbCrLf
    End If
    %>
    <html>
    <head>
    <title><%=cASP%></title>
    </head>
    <body>
    <form>
    <%=strSEL%>
    </form>
    </body>
    </html>


    McKirahan Guest

  4. #3

    Default Re: Populate select field and textbox dynamically - no refresh

    "Targa" <targa1SPAMSUCKS@alltel.net> wrote in message
    news:ObqhmIcREHA.1448@TK2MSFTNGP11.phx.gbl...
    > Ive got a db table with the fields Product_Name and Product_Price.
    >
    > I want to display a pulldown containing the product names and display the
    > price of the selected product in a text box.
    > Currently, I can do the pulldown but to populate the price text box, I
    have
    > to refresh the page.
    >
    > How can I pull all the data in, store it somehow, and have the price
    textbox
    > reflect the selected product in the pulldown without reloading the page?
    >
    > Thanks!

    Here's another solution that requires client-side JavaScript; watch for
    word-wrap.

    <% @Language="VBScript" %>
    <% Option Explicit
    '*
    '* Declare Constants
    '*
    Const cASP = "productx.asp"
    Const cDSN = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ="
    Const cMDB = "products.mdb"
    '*
    '* Declare Variables
    '*
    Dim intPRD
    Dim strPRD
    Dim strSEL
    strSEL = ""
    Dim strSQL
    strSQL = "SELECT * FROM product ORDER BY product_desc"
    Dim intVAR
    intVAR = -1
    Dim strVAR
    strVAR = ""
    '*
    '* Declare Objects
    '*
    Dim objADO
    Set objADO = Server.CreateObject("ADODB.Connection")
    objADO.Open cDSN & Server.MapPath(cMDB)
    Dim objRST
    Set objRST = objADO.Execute(strSQL)
    '*
    '* Read "product" table
    '*
    While Not objRST.EOF
    strSEL = strSEL & "<option value ='" & objRST("product_code") & "'>"
    strSEL = strSEL & objRST("product_desc") & vbCrLf
    intPRD = FormatNumber(objRST("product_price"),2)
    strPRD = objRST("product_code")
    intVAR = intVAR + 1
    strVAR = strVAR & " prod[" & intVAR & "] = '"
    strVAR = strVAR & strPRD & "|" & intPRD & "';" & vbCrLf
    objRST.MoveNext
    Wend
    '*
    '* Destroy Objects
    '*
    Set objRST = Nothing
    Set objADO = Nothing
    %>
    <html>
    <head>
    <title><%=cASP%></title>
    <script type="text/javascript">
    var prod = new Array();
    <%=strVAR%>
    function Assign() {
    var form = document.forms[0];
    form.Txt.value = "";
    var code = form.Sel.options[form.Sel.selectedIndex].value;
    if (code == "") return;
    for (var i=0; i<prod.length; i++) {
    var what = prod[i].split("|");
    if (code == what[0]) {
    form.Txt.value = what[1];
    break;
    }
    }
    }
    </script>
    </head>
    <body>
    <form>
    <b>Product :</b> &nbsp;
    <select name="Sel" onchange="Assign()">
    <option value="">
    <%=strSEL%>
    </select>
    <b>Price :</b> &nbsp;
    <input type="text" name="Txt" size="8" disabled
    style="text-align:right; background-color:#EEEEEE; font-weight:bold">
    </form>
    </body>
    </html>


    McKirahan Guest

  5. #4

    Default Re: Populate select field and textbox dynamically - no refresh

    "Targa" <targa1SPAMSUCKS@alltel.net> wrote in message
    news:ObqhmIcREHA.1448@TK2MSFTNGP11.phx.gbl...
    > Ive got a db table with the fields Product_Name and Product_Price.
    >
    > I want to display a pulldown containing the product names and display the
    > price of the selected product in a text box.
    > Currently, I can do the pulldown but to populate the price text box, I
    have
    > to refresh the page.
    >
    > How can I pull all the data in, store it somehow, and have the price
    textbox
    > reflect the selected product in the pulldown without reloading the page?
    >
    > Thanks!

    Here's another solution that still uses JavaScript but omits "product_code"
    if it's not needed; watch for word-wrap.

    <% @Language="VBScript" %>
    <% Option Explicit
    '*
    '* Declare Constants
    '*
    Const cASP = "productz.asp"
    Const cDSN = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ="
    Const cMDB = "products.mdb"
    '*
    '* Declare Variables
    '*
    Dim strSEL
    strSEL = ""
    Dim strSQL
    strSQL = "SELECT product_desc, product_price"
    strSQL = strSQL & " FROM product ORDER BY product_desc"
    '*
    '* Declare Objects
    '*
    Dim objADO
    Set objADO = Server.CreateObject("ADODB.Connection")
    objADO.Open cDSN & Server.MapPath(cMDB)
    Dim objRST
    Set objRST = objADO.Execute(strSQL)
    '*
    '* Read "product" table
    '*
    Do While Not objRST.EOF
    strSEL = strSEL & "<option value ='"
    strSEL = strSEL & FormatNumber(objRST("product_price"),2)
    strSEL = strSEL & "'>" & objRST("product_desc") & vbCrLf
    objRST.MoveNext
    Loop
    '*
    '* Destroy Objects
    '*
    Set objRST = Nothing
    Set objADO = Nothing
    %>
    <html>
    <head>
    <title><%=cASP%></title>
    <script type="text/javascript">
    function Assign() {
    var form = document.forms[0];
    form.Txt.value = form.Sel.options[form.Sel.selectedIndex].value;
    }
    </script>
    </head>
    <body>
    <form>
    <b>Product :</b> &nbsp;
    <select name="Sel" onchange="Assign()">
    <option value="">
    <%=strSEL%>
    </select>
    <b>Price :</b> &nbsp;
    <input type="text" name="Txt" size="8" disabled
    style="text-align:right; background-color:#EEEEEE; font-weight:bold">
    </form>
    </body>
    </html>


    McKirahan Guest

  6. #5

    Default Re: Populate select field and textbox dynamically - no refresh

    Thanks for all your replies - I found each method very helpful.



    "McKirahan" <News@McKirahan.com> wrote in message
    news:fgruc.20386$4A6.8565@attbi_s52...
    > "Targa" <targa1SPAMSUCKS@alltel.net> wrote in message
    > news:ObqhmIcREHA.1448@TK2MSFTNGP11.phx.gbl...
    > > Ive got a db table with the fields Product_Name and Product_Price.
    > >
    > > I want to display a pulldown containing the product names and display
    the
    > > price of the selected product in a text box.
    > > Currently, I can do the pulldown but to populate the price text box, I
    > have
    > > to refresh the page.
    > >
    > > How can I pull all the data in, store it somehow, and have the price
    > textbox
    > > reflect the selected product in the pulldown without reloading the page?
    > >
    > > Thanks!
    >
    >
    > Here's another solution that still uses JavaScript but omits
    "product_code"
    > if it's not needed; watch for word-wrap.
    >
    > <% @Language="VBScript" %>
    > <% Option Explicit
    > '*
    > '* Declare Constants
    > '*
    > Const cASP = "productz.asp"
    > Const cDSN = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ="
    > Const cMDB = "products.mdb"
    > '*
    > '* Declare Variables
    > '*
    > Dim strSEL
    > strSEL = ""
    > Dim strSQL
    > strSQL = "SELECT product_desc, product_price"
    > strSQL = strSQL & " FROM product ORDER BY product_desc"
    > '*
    > '* Declare Objects
    > '*
    > Dim objADO
    > Set objADO = Server.CreateObject("ADODB.Connection")
    > objADO.Open cDSN & Server.MapPath(cMDB)
    > Dim objRST
    > Set objRST = objADO.Execute(strSQL)
    > '*
    > '* Read "product" table
    > '*
    > Do While Not objRST.EOF
    > strSEL = strSEL & "<option value ='"
    > strSEL = strSEL & FormatNumber(objRST("product_price"),2)
    > strSEL = strSEL & "'>" & objRST("product_desc") & vbCrLf
    > objRST.MoveNext
    > Loop
    > '*
    > '* Destroy Objects
    > '*
    > Set objRST = Nothing
    > Set objADO = Nothing
    > %>
    > <html>
    > <head>
    > <title><%=cASP%></title>
    > <script type="text/javascript">
    > function Assign() {
    > var form = document.forms[0];
    > form.Txt.value = form.Sel.options[form.Sel.selectedIndex].value;
    > }
    > </script>
    > </head>
    > <body>
    > <form>
    > <b>Product :</b> &nbsp;
    > <select name="Sel" onchange="Assign()">
    > <option value="">
    > <%=strSEL%>
    > </select>
    > <b>Price :</b> &nbsp;
    > <input type="text" name="Txt" size="8" disabled
    > style="text-align:right; background-color:#EEEEEE; font-weight:bold">
    > </form>
    > </body>
    > </html>
    >
    >

    Targa Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139