Ask a Question related to ASP Database, Design and Development.
-
Targa #1
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
-
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... -
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... -
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... -
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... -
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... -
McKirahan #2
Re: Populate select field and textbox dynamically - no refresh
"Targa" <targa1SPAMSUCKS@alltel.net> wrote in message
news:ObqhmIcREHA.1448@TK2MSFTNGP11.phx.gbl...have> 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, Itextbox> to refresh the page.
>
> How can I pull all the data in, store it somehow, and have the price> 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
-
McKirahan #3
Re: Populate select field and textbox dynamically - no refresh
"Targa" <targa1SPAMSUCKS@alltel.net> wrote in message
news:ObqhmIcREHA.1448@TK2MSFTNGP11.phx.gbl...have> 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, Itextbox> to refresh the page.
>
> How can I pull all the data in, store it somehow, and have the price> 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>
<select name="Sel" onchange="Assign()">
<option value="">
<%=strSEL%>
</select>
<b>Price :</b>
<input type="text" name="Txt" size="8" disabled
style="text-align:right; background-color:#EEEEEE; font-weight:bold">
</form>
</body>
</html>
McKirahan Guest
-
McKirahan #4
Re: Populate select field and textbox dynamically - no refresh
"Targa" <targa1SPAMSUCKS@alltel.net> wrote in message
news:ObqhmIcREHA.1448@TK2MSFTNGP11.phx.gbl...have> 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, Itextbox> to refresh the page.
>
> How can I pull all the data in, store it somehow, and have the price> 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>
<select name="Sel" onchange="Assign()">
<option value="">
<%=strSEL%>
</select>
<b>Price :</b>
<input type="text" name="Txt" size="8" disabled
style="text-align:right; background-color:#EEEEEE; font-weight:bold">
</form>
</body>
</html>
McKirahan Guest
-
Targa #5
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...the> "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"product_code"> have> > price of the selected product in a text box.
> > Currently, I can do the pulldown but to populate the price text box, I> textbox> > to refresh the page.
> >
> > How can I pull all the data in, store it somehow, and have the price>> > reflect the selected product in the pulldown without reloading the page?
> >
> > Thanks!
>
> Here's another solution that still uses JavaScript but omits> 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>
> <select name="Sel" onchange="Assign()">
> <option value="">
> <%=strSEL%>
> </select>
> <b>Price :</b>
> <input type="text" name="Txt" size="8" disabled
> style="text-align:right; background-color:#EEEEEE; font-weight:bold">
> </form>
> </body>
> </html>
>
>
Targa Guest



Reply With Quote

