Click to See Complete Forum and Search --> : dropdown box question


jennyj
09-01-2003, 10:38 AM
This should be a simple question (I hope)

On my page I have a form
within the form I have 12 dropdown boxes, populated from a database - so far so good!

Each item displayed in the dropdown box has a corresponding value in the database

(in this case, the name of a horse is displayed in the dropdown box, and each horse has a price)

when each of the dropdown boxes has a value, the form is submitted(back to itsself) and the data is added to another table in the database - this also works fine

Now the problem!
What I would like to do is to display the price of the horse selected, as soon as it is selected, rather than when the form is submitted.

If necessary, I can post the zipped file, but I hope I have managed to explain what I am trying to do.

I am aware this may be a JavaScript problem - something to do with onchange - but I know next to nothing about javascript, and have just become confused with the samples I have seen.
Hopefully, someone can talk me through this, and not just direct me to the javascript forum ;)

Thanks a lot
JennyJ

ggriffit
09-01-2003, 02:56 PM
Jenny,
you can do this using ASP, although you are much better off using Javascript to achieve the results that you want. I realise that JS may be a bit difficult for you at the moment. If you email me the code Ill have a look for you.

TBor
09-02-2003, 09:06 AM
Looking at this, one thing you could do is just add the price to the name of the horse in the drop-down list, something like "Horse #1 - $100". Might make it easier, and you don't have to add any scripting to do it.

You're right though about onChange, though. If you add an onChange event handler to the SELECT tag, you can change the values of other page elements whenever the drop-down list selected item is changed. What it changes depends on where you want the price displayed on the screen.

If you can give a bit more info, or some code, I can give you a better answer. For instance, where do you want the price displayed (in an INPUT tag, SPAN, etc.)?

Joe Burns has a brief description of using onChange in Javascript at:
http://www.htmlgoodies.com/primers/jsp/hgjsp_5.html

Hope this helps,
TBor

jennyj
09-02-2003, 09:43 AM
Hi TBor,
Yes, I have already added the price to the name of the horse in the dropdown, thats no problem.
However, the point of displaying the price is so that when I select the next horse, in the next dropdown, I want to display the combined price of the two horses.
Not really bothered where this is displayed, as long as it's there!
This is the page code so far, at the moment the price is only shown for the first dropdown - sorry about the long coding, might be easier to see the problem with the entire page.
Thanks
JennyJ
<%
pagename="Choose your Team"
'--connect to database
set Conn = server.createobject("adodb.connection")
Conn.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ="& Server.Mappath("/db/db.mdb"))
'--use english time format
session.lcid= 2057
'--select everything from table
If Request.QueryString("team_name") <> "" Then
SQL = "SELECT * FROM tblhorses"
set rs = conn.execute (SQL)
Else
Response.Redirect("/index.asp?msg=Please enter your team name and password above")
End If
'-- this bit deals with # of records to show per select box
Const NumPerPage = 27
If Not rs.EOF Then
rs.MoveFirst
rs.PageSize = NumPerPage
End If
'-- the next section deals with updating

If Request.Form("submit") = "submit" Then
'--if submit button is pressed
if request("horse_1") = "" Then
'--check if tblteam contains data for horses,
SQL = "UPDATE tblteam SET horse_1='"& request.form("horse_1")&"',horse_2='"& request.form("horse_2")&"',horse_3='"& request.form("horse_3")&"',horse_4='"& request.form("horse_4")&"',horse_5='"& request.form("horse_5")&"',horse_6='"& request.form("horse_6")&"',horse_7='"& request.form("horse_7")&"',horse_8='"& request.form("horse_8")&"',horse_9='"& request.form("horse_9")&"',horse_10='"& request.form("horse_10")&"',horse_11='"& request.form("horse_11")&"',horse_12='"& request.form("horse_12")&"',temp1='"& request.form("horse_1")&"',temp2='"& request.form("horse_2")&"',temp3='"& request.form("horse_3")&"',temp4='"& request.form("horse_4")&"',temp5='"& request.form("horse_5")&"',temp6='"& request.form("horse_6")&"',temp7='"& request.form("horse_7")&"',temp8='"& request.form("horse_8")&"',temp9='"& request.form("horse_9")&"',temp10='"& request.form("horse_10")&"', temp11='"& request.form("horse_11")&"',temp12='"& request.form("horse_12")&"'WHERE team_name='" & request("team_name") & "'"
'--if the record set for horse_1 is empty, assume the others are also empty
'--and fill in the data from the form.
'--put the values into temp values as well, to make later updating easier
conn.execute SQL
else
'--if tblteam already contains data, store the new values in a new temp fields
SQL = "UPDATE tblteam SET temp1='"& request.form("horse_1")&"', temp2='"& request.form("horse_2")&"', temp3='"& request.form("horse_3")&"', temp4='"& request.form("horse_4")&"', temp5='"& request.form("horse_5")&"', temp6='"& request.form("horse_6")&"', temp7='"& request.form("horse_7")&"', temp8='"& request.form("horse_8")&"', temp9='"& request.form("horse_9")&"', temp10='"& request.form("horse_10")&"', temp11='"& request.form("horse_11")&"', temp12='"& request.form("horse_12")&"'WHERE team_name='" & request("team_name") & "'"
conn.execute SQL
end if
End If
'--finished with submit statement
%>
<!--#include virtual="/head.asp" -->
<p>Your current stable <% if request("horse_1")<>"" then %>
contains the following horses:
<%=request("horse_1")%>, <%=request("horse_2")%>, <%=request("horse_3")%>, <%=request("horse_4")%>, <%=request("horse_5")%>, <%=request("horse_6")%>, <%=request("horse_7")%>, <%=request("horse_8")%>, <%=request("horse_9")%>, <%=request("horse_10")%>, <%=request("horse_11")%>, <%=request("horse_12")%>.
</p>
total points for your stable = <%=request("team_points")%>
<% else %> is empty
<% end if %>
<p>Please pick 12 horses for your stables. You can choose one horse from each selection box.<br />
Each horse has a value, you must keep your selection within a budget of £value. As you select your team, you will see the running total for your stable displayed. If you attempt to select a stable that costs more than your budget, you will be notified, and have to select your horses again.</p>
<p>Your initial selection will take effect immediately.<br />
You can make changes to your stables at any time, however changes will not take effect until the following week, thus changes made at any time before 18:00 Sunday will come into effect on Monday at 10:00. (All times are GMT)</p>

<form name="form1" method="post" action="select.asp?team_name=<%=request("team_name")%>&team_points=<%=request("team_points")%>">
<select name="horse_1">
<option value="<%=request("horse_1")%>"><%=request("horse_1")%></option>
<%
'-- Continue until we get to record 25
do while not rs.eof and iCount < rs.PageSize
%>
<option value="<%=rs("horse")%>"><%=rs("horse")%>, <%=formatCurrency(rs("price"))%></option>
<%
' Get next record
rs.movenext
iCount = iCount + 1
loop
%>
</select>
<br />
<select name="horse_2">
<option value="<%=request("horse_2")%>"><%=request("horse_2")%></option>

<%
'-- Continue until we get to record 50
do while not rs.eof and iCount < rs.PageSize*2
%>
<option value="<%= rs("horse")%>"><%= rs("horse") %></option>
<%
' Get next record
rs.movenext
iCount = iCount + 1
loop
%>
</select>
<br />
<select name="horse_3">
<option value="<%=request("horse_3")%>"><%=request("horse_3")%></option>
<%
'-- Continue until we get to record 75
do while not rs.eof and iCount < rs.PageSize*3
%>
<option value="<%= rs("horse")%>"><%= rs("horse") %></option>
<%
' Get next record
rs.movenext
iCount = iCount + 1
loop
%>
</select>
<br />
<select name="horse_4">
<option value="<%=request("horse_4")%>"><%=request("horse_4")%></option>
<%
'-- Continue until we get to record 100
do while not rs.eof and iCount < rs.PageSize*4
%>
<option value="<%= rs("horse")%>"><%= rs("horse") %></option>
<%
' Get next record
rs.movenext
iCount = iCount + 1
loop
%>
</select>
<br />
<select name="horse_5">
<option value="<%=request("horse_5")%>"><%=request("horse_5")%></option>
<%
'-- Continue until we get to record 125
do while not rs.eof and iCount < rs.PageSize*5
%>
<option value="<%= rs("horse")%>"><%= rs("horse") %></option>
<%
' Get next record
rs.movenext
iCount = iCount + 1
loop
%>
</select>
<br />
<select name="horse_6">
<option value="<%=request("horse_6")%>"><%=request("horse_6")%></option>
<%
'-- Continue until we get to record 150
do while not rs.eof and iCount < rs.PageSize*6
%>
<option value="<%= rs("horse")%>"><%= rs("horse") %></option>
<%
' Get next record
rs.movenext
iCount = iCount + 1
loop
%>
</select>
<br />
<select name="horse_7">
<option value="<%=request("horse_7")%>"><%=request("horse_7")%></option>
<%
'-- Continue until we get to record 175
do while not rs.eof and iCount < rs.PageSize*7
%>
<option value="<%= rs("horse")%>"><%= rs("horse") %></option>
<%
' Get next record
rs.movenext
iCount = iCount + 1
loop
%>
</select>
<br />
<select name="horse_8">
<option value="<%=request("horse_8")%>"><%=request("horse_8")%></option>
<%
'-- Continue until we get to record 200
do while not rs.eof and iCount < rs.PageSize*8
%>
<option value="<%= rs("horse")%>"><%= rs("horse") %></option>
<%
' Get next record
rs.movenext
iCount = iCount + 1
loop
%>
</select>
<br />
<select name="horse_9">
<option value="<%=request("horse_9")%>"><%=request("horse_9")%></option>
<%
'-- Continue until we get to record 225
do while not rs.eof and iCount < rs.PageSize*9
%>
<option value="<%= rs("horse")%>"><%= rs("horse") %></option>
<%
' Get next record
rs.movenext
iCount = iCount + 1
loop
%>
</select>
<br />
<select name="horse_10">
<option value="<%=request("horse_10")%>"><%=request("horse_10")%></option>
<%
'-- Continue until we get to record 250
do while not rs.eof and iCount < rs.PageSize*10
%>
<option value="<%= rs("horse")%>"><%= rs("horse") %></option>
<%
' Get next record
rs.movenext
iCount = iCount + 1
loop
%>
</select>
<br />
<select name="horse_11">
<option value="<%=request("horse_11")%>"><%=request("horse_11")%></option>
<%
'-- Continue until we get to record 275
do while not rs.eof and iCount < rs.PageSize*11
%>
<option value="<%= rs("horse")%>"><%= rs("horse") %></option>
<%
' Get next record
rs.movenext
iCount = iCount + 1
loop
%>
</select>
<br />
<select name="horse_12">
<option value="<%=request("horse_12")%>"><%=request("horse_12")%></option>
<%
'-- Continue until we get to record 300
do while not rs.eof and iCount < rs.PageSize*12
%>
<option value="<%= rs("horse")%>"><%= rs("horse") %></option>
<%
' Get next record
rs.movenext
iCount = iCount + 1
loop
%>
</select>
<br />
<input type="submit" name="submit" value="submit">

</form>
<%
rs.close
set rs = nothing
conn.close
set conn = nothing
%>

<!--#include virtual="/footer.asp" -->