Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
'pretend we have a recordset named rs
Response.Write "<select name=""selFirstSelect"" onChange=""myFormName.action='nameOfThisPage.asp';myFormName.submit();"">"
rs.moveFirst
Do Until rs.EOF
Response.Write "<option value='" & rs("whatever") & "'"
If Request.Form("selFirstSelect") = rs("whatever") Then Response.Write " selected"
Response.Write "> " & rs("whateverElse") & "</option>"
rs.MoveNext
Loop
Response.Write "</select>"
If Request.Form("selSecondSelect") <> "" Then
sql_query3 = "Select...Where service = '" & Request.Form("selSecondSelect") & "'" 'assuming service was a string
sql_query2 = "Select...Where id = " & Request.Form("selFirstSelect") 'assuming id was a number
ElseIf Request.Form("selSelectFirst") <> "" Then
sql_query3 = "Select..." 'select based on id
sql_query2 = "Select...Where id = " & Request.Form("selFirstSelect") 'assuming id was a number
Else
sql_query3 = "Select *..."
sql_query2 = "select *..."
End If
sql_query1 = "select *..." 'always select everything for the first one
<html>
<head>
<title> Shift Selection </title>
<script language="JavaScript">
<!--
var shifts;
function init(){
//to initialize them all to the same times
shifts = new Array(,new Array("monday 1","monday 2","monday 3"), new Array("tuesday 4","tuesday 5","tuesday 6"))
//change day function
function changeDay(elem){
var j, day;
var shiftText;
if(elem.selectedIndex == 0) //if they selected our pretty [select a day] stmt
return false; //do nothing and leave quietly
//Clear the second drop down of all but top [select a shift]
for (i = document.frmFormName.workday.options.length - 1; i >= 1; i--) document.frmFormName.workday.options[i] = null;
document.frmFormName.workday.selectedIndex = 0;
//grab day from select box
day = elem.selectedIndex;
for(j=0;j<shifts[day].length;j++){
document.frmFormName.workday.options[j] = new Option(shifts[day][j],shifts[day][j]);
}
}
//-->
</script>
</head>
<body onLoad="init();">
<form method=POST action="wherever.html" name="frmFormName">
<select name="weekday" onChange="changeDay(this);">
<option>[Select a day]</option>
<option>Monday</option>
<option>Tuesday</option>
</select>
<select name="workday">
<option>[Select a Shift]</option>
</select>
</form>
</body>
</html>
Paper.paper_type PaperGrades.paper_grade
Printer Standard 8.5x11
Printer Glossy Photo Paper 5x7
Printer Ultra-Super-Fine 8.5x11
Printer Ultra-Glossy Photo Paper 5x7
LooseLeaf Yellow Standard Rule 8.5x11
LooseLeaf Yellow Legal Rule 8.5x11
LooseLeaf White Legal Rule 8.5x11
Photocopy Standard 8.5x11
Photocopy Super recycled 8.5x11
Photocopy Barely Better Then Toilet Paper 8.5x11
Photocopy Thicker Then Cardcoard 8.5x11
<script language="javascript">
var dataArray = new Array(<%
If Not rsPaper.EOF Then rsPaper.MoveFirst
Dim last_item
Do Until rsPaper.EOF
'check if the first column item is equal to it's value
' from the previous loop, if not start a new array
If last_item <> rsPaper("paper_type") Then
'if there was a last item, finish the previous array
If len(last_item) > 0 Then Response.Write ")"
'start a new array
Response.Write ",new Array("
'record last item
last_item = rsPaper("paper_type")
End If
'output the second column value preceded by a comma
Response.Write "," & rsPaper("paper_grade")
'queue to next record
rsPaper.MoveNext
Loop
'finish open array if there was a last item
If len(last_item) > 0 Then Response.Write ")"
%>);
function changeOptions(elemOne,elemTwo){
var i;
//clear out previous options leaving the top generic text
for(i = elemTwo.options.length; i >= 1; i--)
elemTwo.options[i] = null;
elemTwo.selectedIndex = 0;
//if the selected index in the first one is 0 escape out
if(elemOne.selectedIndex == 0)
return false;
//populate second one
for(i=1;i<dataArray.length;i++){
elemTwo.options[i] = new Option(dataArray[elemOne.selectedIndex][i],elemOne.selectedIndex][i]);
}
}
</script>
<script language="javascript">
var dataArray = new Array(<%
If Not rsPaper.EOF Then rsPaper.MoveFirst
Dim last_item
Do Until rsPaper.EOF
'check if the first column item is equal to it's value
' from the previous loop, if not start a new array
If last_item <> rsPaper("paper_type") Then
'if there was a last item, finish the previous array
If len(last_item) > 0 Then Response.Write ")"
'start a new array
Response.Write ",new Array("
'record last item
last_item = rsPaper("paper_type")
End If
'output the second column value preceded by a comma
Response.Write ",[highlight]new Array(" & rsPaper("grade_id") & "," & rsPaper("paper_grade") & ")"[/highlight] 'Change [0]
'queue to next record
rsPaper.MoveNext
Loop
'finish open array if there was a last item
If len(last_item) > 0 Then Response.Write ")"
%>);
function changeOptions(elemOne,elemTwo){
var i;
//clear out previous options leaving the top generic text
for(i = elemTwo.options.length; i >= 1; i--)
elemTwo.options[i] = null;
elemTwo.selectedIndex = 0;
//if the selected index in the first one is 0 escape out
if(elemOne.selectedIndex == 0)
return false;
//populate second one
for(i=1;i<dataArray.length;i++){
elemTwo.options[i] = new [highlight]Option(dataArray[elemOne.selectedIndex][i][1],elemOne.selectedIndex][i][0]);[/highlight] 'Change [1]
}
}
</script>
<%
Option Explicit
'bunch of ADO code here to make a connection, retrieve data, etc
Dim rsPaper, ado_conn
Set ado_conn = Server.CreateObject("ADODB.Connection")
ado_conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath("PaperDemo.mdb") & ";" & _
"Persist Security Info=False"
Dim str_sql
str_sql = "SELECT paper_type, grade_id, paper_grade " & _
"FROM Paper INNER JOIN PaperGrade ON Paper.paper_id = PaperGrade.paper_id " & _
"ORDER BY paper_type, paper_grade"
Set rsPaper = ado_conn.Execute(str_sql)
%>
<html>
<head>
<script language="javascript">
var dataArray = new Array(null<%
If Not rsPaper.EOF Then rsPaper.MoveFirst
Dim last_item
Do Until rsPaper.EOF
'check if the first column item is equal to it's value
' from the previous loop, if not start a new array
If last_item <> rsPaper("paper_type") Then
'if there was a last item, finish the previous array
If len(last_item) > 0 Then Response.Write ")"
'start a new array
Response.Write ",new Array(null"
'record last item
last_item = rsPaper("paper_type")
End If
'output the second column value preceded by a comma
Response.Write ",new Array('" & rsPaper("grade_id") & "','" & rsPaper("paper_grade") & "')"
'queue to next record
rsPaper.MoveNext
Loop
'finish open array if there was a last item
If len(last_item) > 0 Then Response.Write ")"
%>);
function changeOptions(elemOne,elemTwo){
var i;
//clear out previous options leaving the top generic text
for(i = elemTwo.options.length; i >= 1; i--)
elemTwo.options[i] = null;
elemTwo.selectedIndex = 0;
//if the selected index in the first one is 0 escape out
if(elemOne.selectedIndex == 0)
return false;
//populate second one
for(i=1;i<dataArray.length;i++){
elemTwo.options[i] = new Option(dataArray[elemOne.selectedIndex][i][1],dataArray[elemOne.selectedIndex][i][0]);
}
}
</script>
</head>
<body>
<form method="POST" action="whatever.asp">
<select name="selType" onChange="changeOptions(this,document.getElementsByName('selGrade')[0])">
<option value="">[ Select Type ]</option>
<%
'the only way the RS could be BOF at this point is if it was empty
If Not rsPaper.BOF Then rsPaper.MoveFirst
Dim last_paper
Do Until rsPaper.EOF
If rsPaper("paper_type") <> last_paper Then
Response.Write "<option>" & rsPaper("paper_type") & "</option>"
last_paper = rsPaper("paper_type")
End If
rsPaper.MoveNext
Loop
%>
</select>
<select name="selGrade">
<option value="">[ Select a Grade ]</option>
</select>
<input type="submit">
</form>
</body>
</html>
var dataArray = new Array(
<%
' this is not real code, just a bare minimum for creating code later
Dim last_id. last_service
Do Until EOF
if last_id is not = id from recordset
if last service was not empty
output a ) to end last service array
if last id was not empty
output a ) to end last id
start a new array for this id: output new Array(
end if
if last_service is not = service from recordset
if last service was not empty
output a ) to end last service
start a new array for this set of areas: output new Array(
end if
output , and area from recordset
MoveNext
Loop
check if last_service <> ""
output a ) to close outstanding areas array
check if last_id <> ""
output a ) to end last services array
%>);