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={dayOfWeek: [{day: "monday",theShifts: ["1","2","3"]},{day:"tuesday",theShifts: ["4","5","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 = frmFormName.workday.options.length - 1; i >= 1; i--) frmFormName.workday.options[i] = null;
frmFormName.workday.selectedIndex = 0;
//grab day from select box
day = elem.selectedIndex-1;
for(j=0;j<shifts.dayOfWeek[day].theShifts.length;j++){
document.frmFormName.workday.options[j] = new Option(shifts.dayOfWeek[day].theShifts[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>
var array = {nameOfSection:[
For each day
output {day:"name of day",theShifts:[
for each shiftfor this day
output "shift name",
next
next
<%
Option Explicit
Dim objRS
'objRS holds a record set that contains records with shift_day, shift_number
' for example
' 1st record: Monday, 1
' 2nd record: Monday, 2
' 3rd record: Monday, 3
' 4th record: Tuesday, 1
' etc
%>
<html>
<head>
<title> Shift Selection </title>
<script language="JavaScript">
<!--
var shifts;
function init(){
//to initialize them all to the same times
shifts={dayOfWeek: [
<%
dim tDay
objRS.MoveFirst
Do Until objRS.EOF
If tDay <> objRS("shift_day") Then 'If not equal to previous, than start a new array element
%>
{day: "<%=objRS("shift_day")%>",theShifts: [
<%
tDay = objRS("shift_day")
End If
%>"<%=objRS("shit_number")%>", <% 'add the shift number to inner array
objRS.MoveNext
If tDay <> objRS("shift_day") Then 'If next not equal to current, end the array element
Response.Write "]},"
End If
Loop
%>
}
//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 = frmFormName.workday.options.length - 1; i >= 1; i--) frmFormName.workday.options[i] = null;
frmFormName.workday.selectedIndex = 0;
//grab day from select box
day = elem.selectedIndex-1;
for(j=0;j<shifts.dayOfWeek[day].theShifts.length-1;j++){
document.frmFormName.workday.options[j] = new Option(shifts.dayOfWeek[day].theShifts[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>
<%
objRS.MoveFirst
tDay = ""
Do Until objRS.EOF
If tDay <> objRS("shift_day") Then
%>
<option><%=objRS("shift_day")%></option>
<%
tDay = objRS("shift_day")
End If
objRS.MoveNext
Loop
%>
</select>
<select name="workday">
<option>[Select a Shift]</option>
</select>
</form>
</body>
</html>
var array = {nameOfSection:[
For each ID
output {id:"value of ID",{services:[
for each service for this ID
output {"service name",{areas:[
for each area for this service
output "area name"
next
next
next
rs_all.MoveFirst
'escaping to javascript to write some variables, usually I would
' response.write these but I wanted to clarify the change from
' ASP to javascript
%>
var tempID, tempService
var myArray = {chainedData:[<% 'back to ASP to handle outputting the recordset
Do Until rs_all.EOF
'if this id is not equal to the last one
If rs_all("ID") <> tempID Then
'if this isn't the first run through
If tempID <> "" Then
'end the previous id block
Response.Write "},"
End If
'Start a new ID block
Response.Write "{id:""" & rs_all("ID") & """,{services:["
End If
'Ok, now we do the same thing for service because the services are block as well instead of just comma-delimited lists in the array
If rs_all("service") <> tempService Then
'if this isn't the first run through
If tempService <> "" Then
'end the previous id block
Response.Write "},"
End If
'Start a new Service block
Response.Write "{serviceName:""" & rs_all("service") & """,{services:["
End If
'Now we just need to output the areas in a comma delimited fashion
'check if this is a new service, if so we don't need a preceding comma
If tempService = rs_all("service") Then
Response.Write ","
End If
'output area
Response.Write """" & rs_all("area") & """"
'set the tempID and tempService variables
tempID = rs_all("id")
tempService = rs_all("service")
'incrememnt recordset
rs_all.MoveNext
Loop
//this would work
var shifts = new Array("Monday",1,2,3)
var shifts2 = new Array("Tuesday",4,5,6)
var days = new Array(shifts, shifts2)
var theShifts = new Array(1,2,3);
var theShifts2 = new Array(1,2,3);
var day = new Array("Monday",shifts);
var day2 = new Array("Tuesday",shifts2);
var shifts = new Array(day, day2);
For Each Id
For Each service
for each area
add this area to an areas array (with a counter)
next
add service name to services array followed by the areas array for this service
Next
add the correct services arrays to each id array
Next
add the id arrays to the ids array