ASP form auto populate based upon user input

M

Mike Willard

I am way new to web page design. I know what I am trying to
accomplish. I wish to have a form that a user will fill out for
opening trouble tickets. The user will have a dropdown to choose store
number (that is working) from an MDB file. The City, State, Address
and Phone number will all be filled in based upon a query on the
database using the store number selected from the dropdown as part of
the query. I am assuming that I will need to kick the data to another
form and display that form to the user so they input other data before
submitting which will email to the help desk. I am assuming that I
will use onchange from the storenumber dropdown. Anyway I am really
struggling. I want the first form and the second form to look exactly
the same except the second one will have data filled in based upon the
choice from the dropdown box, and it will have a submit button on the
bottom of the form. Attached is the current code (reminder be kind
this is no masterpiece).

<%@ LANGUAGE="VBScript" %>

<%
' The adovbs.inc file must be in the root directory
' of your webserver for this example to work

Set oConn = Server.CreateObject("ADODB.Connection")
Set oRs = Server.CreateObject("ADODB.Recordset")
oConn.Open "DRIVER={Microsoft Access Driver (*.mdb)};
DBQ=d:\inetpub\wwwroot\bbros\call.mdb"

strSQL = "SELECT * FROM STORE"

oRs.Open strSQL, oConn, 3, 3

WHILE NOT oRs.EOF

' Change the 2 to a 1 to change the default option selected

IF oRs("store_num") = 1 THEN
strStore_num = strStore_num & "<option selected value=" &
oRs("city") & ">" & oRs("store_num") & "</option>"
ELSE
strStore_num = strStore_num & "<option value=" & oRs("city") & ">"
& oRs("store_num") & "</option>"

END IF

IF oRs("City") = "Lufkin" THEN
strCity = strCity & "<option selected value=" & oRs("store_num") &
">" & oRS("city") & "</option>"
ELSE
strCity = strCity & "<option value=" & oRs("store_num") & ">" &
oRs("city") & "</option>"

END IF

oRs.MoveNext

WEND

oRs.Close
oConn.Close

%>


<html>
<head>

<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<title>Trouble Ticket</title>

</head>

<body>

<form method="POST" action="call.asp" name="BbrosTrouble">
<table border="1" width="640" id="table1" height="480"
bordercolor="#000000" bgcolor="#C0C0C0">
<tr>
<td colspan="8"><b><font face="Tahoma" size="1">
<img border="0" src="../graphics/bclogo1.jpg" width="168"
height="82"></font></b></td></tr><tr>
<td width="98%" colspan="8">&nbsp;</td>
</tr>
<tr>
<td width="8%"><b><font face="Tahoma"
size="1">Subject:</font></b></td><td width="89%" colspan="7"><font
face="Tahoma" size="1">
<input name="Subject" size="67" style="font-family:Tahoma;
font-size:8pt; background-color:#C0C0C0" value="Brookshire Brothers
Trouble Ticket #" </font <% =("Ticket") %>,></td></tr><tr>
<td width="97%" colspan="8">&nbsp;</td>
</tr>
<tr>
<td width="8%"><b><font face="Tahoma" size="1">Trouble Ticket
#</font></b></td><td width="26%"><font face="Tahoma" size="1">
<input name="Ticket" size="20" style="font-size:8pt;
font-family:Tahoma"></font></td><td width="12%"><b><font face="Tahoma"
size="1">Store #</font></b></td><td width="26%">
<table BORDER="0">
<tr>
<td>
<select size="1" name="Store_Num"
ONCHANGE=BbrosTrouble.submit()>
<option VALUE=<%=strStore_num%>
</option>

</td>
</tr>
</table>
<nobr>
</nobr></td><td width="6%"><b><font face="Tahoma"
size="1">City</font></b></td><td width="26%" colspan="3">
<input type="text" name="City" size="20" <option value=<%=strCity%>
</option style="font-family: Tahoma; font-size: 8pt">&nbsp;


</select></nobr></td></tr><tr>
<td width="8%"><b><font face="Tahoma"
size="1">Lane/Dept</font></b></td><td width="26%"><font face="Tahoma"
size="1">
<input name="Lane" size="20" style="font-family:Tahoma;
font-size:8pt"></font></td><td width="12%"><b><font face="Tahoma"
size="1">
Phone #</font></b></td><td width="26%">
<input NAME="Phone" SIZE="20" style="font-family: Tahoma;
font-size: 8pt"></td><td width="6%"><b><font face="Tahoma" size="1">
Address</font></b></td><td width="26%" colspan="3">
<input NAME="Street" SIZE="28" style="font-family: Tahoma;
font-size: 8pt"></td></tr><tr>
<td width="8%"><b><font face="Tahoma" size="1">Corporate
Contact</font></b></td><td width="26%"><font face="Tahoma" size="1">
<input name="Corp_contact" size="20" style="font-family:Tahoma;
font-size:8pt"></font></td><td width="12%"><b><font face="Tahoma"
size="1">Store Contact</font></b></td><td width="26%"><font
face="Tahoma" size="1">
<input name="Store_contact" size="20" style="font-family:Tahoma;
font-size:8pt"></font></td><td width="11%" colspan="2"><b><font
face="Tahoma" size="1">Priority</font></b></td><td width="11%"
colspan="2"><font face="Tahoma" size="1">
<select size="1" name="Priority" style="font-family:Tahoma;
font-size:8pt">
<option value="1">1- Priority 1 (Emergency)</option>
<option selected value="2">2- Priority 2 (Next Business Day)
</option>
<option value="3">3- Priority 3 (When in Area)</option>
</select></font></td></tr><tr>
<td width="8%"><b><font face="Tahoma" size="1">Call
Date</font></b></td><td width="26%"><font face="Tahoma" size="1">
<input name="Date" size="20" style="font-family:Tahoma;
font-size:8pt" value="<%=Date()%>"></font></td><td
width="12%"><b><font face="Tahoma" size="1">Call
Time</font></b></td><td width="26%"><font face="Tahoma" size="1">
<input name="Time" size="20" style="font-family:Tahoma;
font-size:8pt" value="<%=Time()%>"></font></td><td width="6%"><b><font
face="Tahoma" size="1">New Call</font></b></td><td width="3%">
<input type="radio" value="New_Call" checked
name="R1"></td><td width="6%">
<p align="right"><b><font face="Tahoma"
size="1">Re-Call</font></b></td><td width="15%">
<input type="radio" name="R1"
value="Re_Call"></td></tr><tr>
<td width="98%" valign="top" colspan="8">&nbsp;</td>
</tr>
<tr>
<td width="8%" valign="top"><b><font face="Tahoma" size="1">Call
Summary</font></b></td><td width="89%" colspan="7"><font
face="Tahoma" size="1">
<input name="Summary" size="67" style="font-family:Tahoma;
font-size:8pt"></font></td></tr><tr>
<td width="99%" valign="top" colspan="8">&nbsp;</td>
</tr>
<tr>
<td width="8%" valign="top"><font face="Tahoma" size="1">
<span style="vertical-align: text-top; font-weight: 700">Call
Details</span></font></td><td width="89%" colspan="7"><font
face="Tahoma" size="1">
<textarea rows="7" name="Detail" cols="65"
style="font-family:Tahoma;
font-size:8pt"></textarea></font></td></tr></table><p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p></html>

<%
conn.close
set conn = Nothing
%>
 
S

Stefan B Rusynko

You have some very mangled HTML and ASP
- your option tags are invalid
- your While / Wend needs to be within the page not the head section and can not ref vague options

Suggest you take a look at some practical samples of valid ASP like at asp101.com
- say http://asp101.com/samples/db_pulldown_linked.asp?id=3

PS remove all your inline styles from the input tags
- not globally supported and in many cases the form will not display
--




| I am way new to web page design. I know what I am trying to
| accomplish. I wish to have a form that a user will fill out for
| opening trouble tickets. The user will have a dropdown to choose store
| number (that is working) from an MDB file. The City, State, Address
| and Phone number will all be filled in based upon a query on the
| database using the store number selected from the dropdown as part of
| the query. I am assuming that I will need to kick the data to another
| form and display that form to the user so they input other data before
| submitting which will email to the help desk. I am assuming that I
| will use onchange from the storenumber dropdown. Anyway I am really
| struggling. I want the first form and the second form to look exactly
| the same except the second one will have data filled in based upon the
| choice from the dropdown box, and it will have a submit button on the
| bottom of the form. Attached is the current code (reminder be kind
| this is no masterpiece).
|
| <%@ LANGUAGE="VBScript" %>
|
| <%
| ' The adovbs.inc file must be in the root directory
| ' of your webserver for this example to work
|
| Set oConn = Server.CreateObject("ADODB.Connection")
| Set oRs = Server.CreateObject("ADODB.Recordset")
| oConn.Open "DRIVER={Microsoft Access Driver (*.mdb)};
| DBQ=d:\inetpub\wwwroot\bbros\call.mdb"
|
| strSQL = "SELECT * FROM STORE"
|
| oRs.Open strSQL, oConn, 3, 3
|
| WHILE NOT oRs.EOF
|
| ' Change the 2 to a 1 to change the default option selected
|
| IF oRs("store_num") = 1 THEN
| strStore_num = strStore_num & "<option selected value=" &
| oRs("city") & ">" & oRs("store_num") & "</option>"
| ELSE
| strStore_num = strStore_num & "<option value=" & oRs("city") & ">"
| & oRs("store_num") & "</option>"
|
| END IF
|
| IF oRs("City") = "Lufkin" THEN
| strCity = strCity & "<option selected value=" & oRs("store_num") &
| ">" & oRS("city") & "</option>"
| ELSE
| strCity = strCity & "<option value=" & oRs("store_num") & ">" &
| oRs("city") & "</option>"
|
| END IF
|
| oRs.MoveNext
|
| WEND
|
| oRs.Close
| oConn.Close
|
| %>
|
|
| <html>
| <head>
|
| <meta http-equiv="Content-Language" content="en-us">
| <meta http-equiv="Content-Type" content="text/html;
| charset=windows-1252">
| <title>Trouble Ticket</title>
|
| </head>
|
| <body>
|
| <form method="POST" action="call.asp" name="BbrosTrouble">
| <table border="1" width="640" id="table1" height="480"
| bordercolor="#000000" bgcolor="#C0C0C0">
| <tr>
| <td colspan="8"><b><font face="Tahoma" size="1">
| <img border="0" src="../graphics/bclogo1.jpg" width="168"
| height="82"></font></b></td></tr><tr>
| <td width="98%" colspan="8">&nbsp;</td>
| </tr>
| <tr>
| <td width="8%"><b><font face="Tahoma"
| size="1">Subject:</font></b></td><td width="89%" colspan="7"><font
| face="Tahoma" size="1">
| <input name="Subject" size="67" style="font-family:Tahoma;
| font-size:8pt; background-color:#C0C0C0" value="Brookshire Brothers
| Trouble Ticket #" </font <% =("Ticket") %>,></td></tr><tr>
| <td width="97%" colspan="8">&nbsp;</td>
| </tr>
| <tr>
| <td width="8%"><b><font face="Tahoma" size="1">Trouble Ticket
| #</font></b></td><td width="26%"><font face="Tahoma" size="1">
| <input name="Ticket" size="20" style="font-size:8pt;
| font-family:Tahoma"></font></td><td width="12%"><b><font face="Tahoma"
| size="1">Store #</font></b></td><td width="26%">
| <table BORDER="0">
| <tr>
| <td>
| <select size="1" name="Store_Num"
| ONCHANGE=BbrosTrouble.submit()>
| <option VALUE=<%=strStore_num%>
| </option>
|
| </td>
| </tr>
| </table>
| <nobr>
| </nobr></td><td width="6%"><b><font face="Tahoma"
| size="1">City</font></b></td><td width="26%" colspan="3">
| <input type="text" name="City" size="20" <option value=<%=strCity%>
| </option style="font-family: Tahoma; font-size: 8pt">&nbsp;
|
|
| </select></nobr></td></tr><tr>
| <td width="8%"><b><font face="Tahoma"
| size="1">Lane/Dept</font></b></td><td width="26%"><font face="Tahoma"
| size="1">
| <input name="Lane" size="20" style="font-family:Tahoma;
| font-size:8pt"></font></td><td width="12%"><b><font face="Tahoma"
| size="1">
| Phone #</font></b></td><td width="26%">
| <input NAME="Phone" SIZE="20" style="font-family: Tahoma;
| font-size: 8pt"></td><td width="6%"><b><font face="Tahoma" size="1">
| Address</font></b></td><td width="26%" colspan="3">
| <input NAME="Street" SIZE="28" style="font-family: Tahoma;
| font-size: 8pt"></td></tr><tr>
| <td width="8%"><b><font face="Tahoma" size="1">Corporate
| Contact</font></b></td><td width="26%"><font face="Tahoma" size="1">
| <input name="Corp_contact" size="20" style="font-family:Tahoma;
| font-size:8pt"></font></td><td width="12%"><b><font face="Tahoma"
| size="1">Store Contact</font></b></td><td width="26%"><font
| face="Tahoma" size="1">
| <input name="Store_contact" size="20" style="font-family:Tahoma;
| font-size:8pt"></font></td><td width="11%" colspan="2"><b><font
| face="Tahoma" size="1">Priority</font></b></td><td width="11%"
| colspan="2"><font face="Tahoma" size="1">
| <select size="1" name="Priority" style="font-family:Tahoma;
| font-size:8pt">
| <option value="1">1- Priority 1 (Emergency)</option>
| <option selected value="2">2- Priority 2 (Next Business Day)
| </option>
| <option value="3">3- Priority 3 (When in Area)</option>
| </select></font></td></tr><tr>
| <td width="8%"><b><font face="Tahoma" size="1">Call
| Date</font></b></td><td width="26%"><font face="Tahoma" size="1">
| <input name="Date" size="20" style="font-family:Tahoma;
| font-size:8pt" value="<%=Date()%>"></font></td><td
| width="12%"><b><font face="Tahoma" size="1">Call
| Time</font></b></td><td width="26%"><font face="Tahoma" size="1">
| <input name="Time" size="20" style="font-family:Tahoma;
| font-size:8pt" value="<%=Time()%>"></font></td><td width="6%"><b><font
| face="Tahoma" size="1">New Call</font></b></td><td width="3%">
| <input type="radio" value="New_Call" checked
| name="R1"></td><td width="6%">
| <p align="right"><b><font face="Tahoma"
| size="1">Re-Call</font></b></td><td width="15%">
| <input type="radio" name="R1"
| value="Re_Call"></td></tr><tr>
| <td width="98%" valign="top" colspan="8">&nbsp;</td>
| </tr>
| <tr>
| <td width="8%" valign="top"><b><font face="Tahoma" size="1">Call
| Summary</font></b></td><td width="89%" colspan="7"><font
| face="Tahoma" size="1">
| <input name="Summary" size="67" style="font-family:Tahoma;
| font-size:8pt"></font></td></tr><tr>
| <td width="99%" valign="top" colspan="8">&nbsp;</td>
| </tr>
| <tr>
| <td width="8%" valign="top"><font face="Tahoma" size="1">
| <span style="vertical-align: text-top; font-weight: 700">Call
| Details</span></font></td><td width="89%" colspan="7"><font
| face="Tahoma" size="1">
| <textarea rows="7" name="Detail" cols="65"
| style="font-family:Tahoma;
| font-size:8pt"></textarea></font></td></tr></table><p>&nbsp;</p>
| <p>&nbsp;</p>
| <p>&nbsp;</p>
| <p>&nbsp;</p>
| <p>&nbsp;</p>
| <p>&nbsp;</p>
| <p>&nbsp;</p>
| <p>&nbsp;</p>
| <p>&nbsp;</p>
| <p>&nbsp;</p>
| <p>&nbsp;</p></html>
|
| <%
| conn.close
| set conn = Nothing
| %>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top