Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I update text field after user selects from dropdown list?

Status
Not open for further replies.

sschrupp

Programmer
Feb 23, 2007
25
US
I'm new to HTML, ASP, etc. so I hope someone can offer some suggestions!

I'm trying to create an order web page for my company. So far I've managed to figure out how to access my Access database, create a log-in page, and a dropdown list populated from my database by reading tons of various posts and websites like this one.

Now I'm coming up against a wall, and all the searching and reading isn't helping me much any more. So here's what I'm looking to do now.

When the user selects a promotion from the dropdown list, enters a quantity, and clicks the "Add Item" button I want to add that item to a temporary table and display the items added to a table or something below the form.

My first step is figuring out how to get the value the user selects from the dropdown. I'll then use that value to look up the promotion's cost.

Then I need to figure out how to add that item to a table on the page after the user clicks the button without clearing out the rest of the page.

Then I need to figure out how to take all the items they've added and create the order when they hit the complete button.

Code is below. Please help!
Code:
<%@ LANGUAGE="VBSCRIPT" %>
<!-- #include file = "const.asp" -->
<!--#include virtual="/includes/commonfunctions.asp"-->
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
</HEAD>
<BODY>
<%
sub PromotionDropDownList()

dim objRs1, objRs2, SQLstring, strPromoName, strPromoCost, strPromoID

Set objRs1 = Server.CreateObject("ADODB.Recordset")
Set objRs2 = Server.CreateObject("ADODB.Recordset")

'Get the list of promotions
SQLstring = "select * from tblpromotions"
objRs1.Open SQLstring, objConn

Response.Write "<select name=""dropdownlist"">" 
Response.Write "<option selected=""selected"" value="""">Choose....</option>"

While objrs1.EOF = false
strPromoName = objrs1("PromoName")
strPromoCost = objrs1("PromoCost")
strPromoID = objrs1("PromoID")
'Response.Write "<option value=""sqdorders.asp"">" & objrs1.Fields("PromoName").Value & "</option>" & vbCrLf
Response.Write "<option value=" & "'" & strPromoID & "'" & ">" & strPromoName & "</option>"

objrs1.movenext
Wend
Response.Write "</select>" 

'This doesn't seem to work. strpromoid doesn't display anything!
strPromoID = Request.Form("dropdownlist")
Response.Write "<p align=center>PromoID is: " & strpromoid & "</p>"

end sub

dim objRs1, objRs2, SQLstring
dim txtLogin, strDistID, strDealerName, strDealerAddress, txtDropChoice
dim strDealerCity, strDealerState, strDealerZip, strPromoID

txtlogin = "bob"
'get the login from the session variable given by the log-in page
'txtlogin = session("txtlogin")
Response.Write "login was " & txtlogin

Set objRs1 = Server.CreateObject("ADODB.Recordset")
Set objRs2 = Server.CreateObject("ADODB.Recordset")

'get the user's associated distributor ID number
SQLstring = "select * from tblpassword where pwlogin = '" & txtlogin & "'"
objRs1.Open SQLstring, objConn

strDistID = objrs1("distid")

'get the distributor's address and stuff
SQLstring = "select * from tbldistributors where distid = '" & strdistid & "'"
objRs2.Open SQLstring, objConn

strDealerName = objrs2("distname")
strDealerAddress = objrs2("distadd1")
strDealerCity = objrs2("distcity")
strDealerState = objrs2("diststate")
strDealerZip = objrs2("distzip")

objRs1.Close
objRs2.Close

Response.Write "<P align=center><STRONG><U> Orders</U></STRONG></P>"
Response.Write "<table align=center width=620>"
Response.Write "<tr>"
  Response.Write "<td>"
'Display Distributor number
      Response.Write "<P align=left>Distributor Number:</P> </td>"
  Response.Write "<td>"
      Response.Write "<P align=left><INPUT id=distnum name=distnum value =" & strdistid & " size=6></P></td>"
Response.Write "</tr>"
Response.Write "<tr>"
  Response.Write "<td>"
'Display Distributor name
      Response.Write "<P align=left>Distributor Name:</P> </td>"
  Response.Write "<td>"
      Response.Write "<P align=left><INPUT id=distname name=distname value =" & "'" & strDealerName & "'" & " size=38></P></td>"
Response.Write "</tr>"
Response.Write "<tr>"
	Response.Write "<td>"
'Display Distributor address
      Response.Write "<P align=left>Street Address:</P> </td>"
	Response.Write "<td>"
      Response.Write "<P align=left><INPUT id=distadd  name=distadd value =" & "'" & strDealerAddress & "'" & " size=49></P></td>"
Response.Write "</tr>"
Response.Write "<tr>"
	Response.Write "<td>"
'Display Distributor city, state, zip
      Response.Write "<P align=left>City, State, Zipcode:</P> </td>"
	Response.Write "<td>"
      Response.Write "<P align=left><INPUT id=distcity name=distcity value =" & "'" & strDealerCity & "'" & " size=30>,&nbsp;" _
		& "<INPUT id=diststate name=diststate value =" & strDealerState & " size=3>&nbsp;" _
		& "<INPUT id=distzip name=distzip value =" & "'" & strDealerZip & "'" & " size=8></P></td>"
Response.Write "</tr>"
Response.Write "</table>"

Response.Write "<form name=""promolist"" action=""sqdorders.asp"" method=""post"">"
Response.Write "<table align=center width=650>"
Response.Write "<tr>"
	Response.Write "<td align=left>Please select a promotion to add:</td>"
Response.Write "</tr>"
Response.Write "<table align=center width=650>"
Response.Write "<tr>"
	Response.Write "<td>Promotion:</td>"
	Response.Write "<td>"
	'create the dropdown list
	call PromotionDropDownList() 
	Response.Write "</td>"
	'User enters the quantity they want to order
	Response.Write "<td>Qty:</td>"
	Response.Write "<td><INPUT id=orderqty name=orderqty size=7></td>"
	'Need to create code to look up the promotion's cost and multiply by quantity
	Response.Write "<td>Total Cost:</td>"
	Response.Write "<td><INPUT id=ordercost name=ordercost size=17></td>"
Response.Write "</tr>"
Response.Write "</table>"

'just random stuff I'm trying that doesn't seem to work
'txtDropChoice = Request.Form("dropdownlist")
'if Request.form("promoname") = null then
'	Response.Write "<p>nothing selected</p>"
'else
'	Response.Write "<P align=center>you selected: " & Request.Form("dropdownlist") & "</p>"
'end if
'txtDropChoice = document.promolist.dropdownlist.value
'strPromoID = session("strPromoID")
'Response.Write "<P align=center>you selected: " & strpromoid & "</p>"
'Response.Write "<P align=center>you selected: " & txtDropChoice & "</p>"
%>
<P align=center>*dropdown shows all promotions available to them. Total cost updates after the QTY is 
entered*</p>
</form>
<P align=center>
<INPUT id=submit1 type=submit value="Add Item" name=submit1><BR>
*places promotion ordered into list below*
</P>
<P align=left>Items Added:</P>
<P align=left>*table that shows every item put into 
current order. Should maybe have links to edit/delete line items* </P>
<P align=left>*Record<BR>*Record<BR>*...</P>
<P align=left><INPUT type=submit value="Complete Order"><BR>*brings user to confirmation page*</P>
<P align=left>&nbsp;</P>
<P align=left>Order History (Last 5 orders...):</P>
<P align=left>*Record<BR>*Record<BR>*...<BR>*a list of last 5(?) orders*</P>
<P align=left><INPUT type=submit value="Detailed History Report"><BR>
*opens the detailed reports*</P>

</BODY></HTML>
 
My first step is figuring out how to get the value the user selects from the dropdown. I'll then use that value to look up the promotion's cost.

On the page specified as the [tt]action[/tt] of your HTML [tt]<form>[/tt] you can fetch the selected item with something like:
[tt]x = Request.Form("dropdownlist")[/tt]

Then the value can be used to construct an SQL query to pull the needed values from the database:[tt]
SQLstring = "select PromoCost " _
& "from tblpromotions " _
& "where PromoID = " & x
objRs1.Open SQLstring, objConn
if not objRs1.EoF then
SelectedItemCost = objRs1("PromoCost")
end if
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top