Active Server Pages and VBScript codes (Microsoft products)

Validation on presentation-page of some input form items...     working
<script language="JavaScript">
function formValidation() 
{
 if  ((document.form.textboxname.value.substr(0,1) == " ")	<!--  first character in text box is empty  //-->
   || (document.form.textboxname.value == "")				<!--  text box is empty  //-->
   || (document.form.textboxname.value == null)) 	  	  	<!--  text box is empty  //-->
	{
	 alert("Invalid Text Box Name");
	 document.form. textboxname.focus();
	 return false;
	}

 if  ((document.form.textbox1.value == "")
   && (document.form.textbox1.value == "")
   && (document.form.textbox2.value == "")
   && (document.form.textbox3.value == "") 
   && (document.form.optionchoices.selectedIndex == "0"))
	{
	 alert("At least one field must contain data");
	 document.form.textbox1.focus();
	 return false;
	}
  if (document.form.isCheckbox1.checked) { }
  else if (document.form.isCheckbox2.checked) { }
  else if (document.form.isCheckbox3.checked) { }
  else 
	{
	 alert("One of the checkbox must be selected");
	 document.form.isCheckbox1.focus();
	 return false;
	}
  if ((!document.form.radiobutton[0].checked)
   && (!document.form.radiobutton[1].checked))
	{
	 alert("Must select one radio button");
	 return false;
	}
  if (document.form.radiobutton[0].checked)
	{
	 alert("Radio selection must be Yes [1]");
	 return false;
	}
  if ((document.form.radiobutton[1].checked)
   && (document.form.radiotxtbx.value == "" ))
	{
	 alert("If Radio Yes, must include radiotxtbx name [0]");
	 return false;
	}
}
</script>

Samples of input form types...
<form action="form_resp.asp" method="post" name="form" onSubmit="return formValidation ()">
<input type="text" name="textboxname" size="20" maxlength="20" alt="enter name">
<input type="text" name="textbox1" size="10">
<input type="text" name="textbox2" size="15">
<input type="text" name="textbox3" size="20">
<input type="checkbox" name="isCheckbox1">CheckBox 1
<input type="checkbox" name="isCheckbox2">CheckBox 2
<input type="checkbox" name="isCheckbox3">CheckBox 3
<input type="radio" name="radiobutton" value="radioNo">No
<input type="radio" name=" radiobutton " value="radioYes">Yes,
<input type="text" name="radiotxtbx" size="20" maxlength="20">
<input type="checkbox" name="radioChkbx1">Radio,Checkbox 1
<input type="checkbox" name="radioChkbx2">Radio,Checkbox 2
<input type="checkbox" name="radioChkbx3">Radio,Checkbox 3
<select name="optionchoices">
	<option value=""></option>
	<option value="option1">one</option>
	<option value="option2">two</option>
	<option value="option3">three</option>
</select>
<select name="multiplechoices" multiple size="4">>
	<option value=""></option>
	<option value="choice1">one</option>
	<option value="choice2">two</option>
	<option value="choice3">three</option>
</select>
<input type="submit" name="submit_form" value=" SEARCH ">     
<input type="reset" name="reset_form" value=" CLEAR ">
</form>

Display exsiting record within input form...
<tr>
   <td>Input Name</td>
   <td><%Response.Write rsRecords.Fields("textboxname")%> </td>
   <td><input type="text" name="txtInputName" size="30" maxlength="30" value="<%Response.Write rsRecords.Fields("textboxname")%>"></td>
</tr>
<tr>
   <td>Checkbox #1</td>
   <td><%Response.Write rsRecords.Fields("isCheckbox1")%> </td>
   <td><input type="checkbox" name="newCheckbox1" value="1"<<% if rsRecords.Fields("isCheckbox1")=True then %> checked <% end if %>></td>
</tr>

Pass a value to a second page...
1st page: <a href="whatever.asp?ID=<%=rsRecords.Fields("uniqueID")%>"><%Response.Write rsRecords.Fields("aFieldName")%></a>
   appears as: Content of corresponding aFieldName
   link will be: whatever.asp?ID=1234 
2nd page: <%Request.QueryString("ID")%>

Additional validations on  ASP (middle-tier) page of some input form items for interactivity with a data base...
<%@ LANGUAGE = VBSCRIPT %>
<% OPTION EXPLICIT %>

<% 
Dim varErrorFlag
Dim varErrorNum
Dim ErrorArray()
varErrorNum = 0
varErrorFlag = "N"

IF Request.Form("textboxname ") = "" THEN		' text box is empty
varErrorFlag = "Y" 					' set the error flag
	redim Preserve ErrorArray(varErrorNum)		' enlarge the error array to handle this error
	ErrorArray(varErrorNum) = "<br>Application/Web Site name is required<BR>"   
							' populate the array entry
	varErrorNum = varErrorNum + 1 			' Add 1 to the error counter
END IF

Dim varisEmpty						' one checkbox selection is required
    varisEmpty = "Y" 					' Set CheckBox flag to Empty
	IF Request.Form("isCheckbox1") = "on" THEN
	varisEmpty = "N" 				' set flag to is Not Empty
	END IF
	IF Request.Form("isCheckbox2") = "on" THEN
	varisEmpty = "N" 				' set flag to is Not Empty
	END IF
	IF Request.Form("isCheckbox3") = "on" THEN
	varisEmpty = "N" 				' set flag to is Not Empty
	END IF
IF  varisEmpty = "Y"  THEN
    varErrorFlag = "Y" 					' set the error flag
	redim Preserve ErrorArray(varErrorNum)
	ErrorArray(varErrorNum) = "<br>A Checkbox selection is required<BR>" 
	varErrorNum = varErrorNum + 1 	
END IF

IF Request.Form("radiobutton") = "" THEN		' one radio button (yes or no) must be on
    varErrorFlag = "Y" 					' set the error flag
	redim Preserve ErrorArray(varErrorNum)	
	ErrorArray(varErrorNum) = "<br>Yes or No for Radio Button must be selected<BR>" 
	varErrorNum = varErrorNum + 1 		
END IF

' if radio button = yes, text box input is also required

IF Request.Form("radiobutton ") = "radioYes" AND Request.Form("radiotxtbx")= "" THEN
    varErrorFlag = "Y" 					' set the error flag
	redim Preserve ErrorArray(varErrorNum)	
	ErrorArray(varErrorNum) = "<br>If Yes for Radio Button, text box input is required<BR>" 
	varErrorNum = varErrorNum + 1 		
END IF

Dim varradEmpty						' if radio button = yes, a check box is also required
    varradEmpty = "Y" 					' set Radio Button flag to Empty
	IF Request.Form("radioChkbx1") = "on" THEN
	varradEmpty = "N" 				' set flag to is Not Empty
	END IF
	IF Request.Form("radioChkbx2") = "on" THEN
	varradEmpty = "N" 				' set flag to is Not Empty
	END IF
	IF Request.Form("radioChkbx3") = "on" THEN
	varradEmpty = "N" 				' set flag to is Not Empty
	END IF
IF  Request.Form("radiobutton") = " radioYes " AND varradEmpty = "Y"  THEN
    varErrorFlag = "Y" 					' set the error flag
	redim Preserve ErrorArray(varErrorNum) 	
	ErrorArray(varErrorNum) = "<br> If Yes for Radio Button, a check box must be selected<BR>" 
	varErrorNum = varErrorNum + 1 		
END IF

IF  Request.Form("textbox1") = "" AND _			' one text field input is required
      Request.Form("textbox2") = "" AND _
      Request.Form("textbox3") = "" THEN
      varErrorFlag = "Y" 				' set the error flag
	redim Preserve ErrorArray(varErrorNum)	 
	ErrorArray(varErrorNum) = "At least one text field input is required<BR>" 
	varErrorNum = varErrorNum + 1 		
END IF
%>

ASP Server Variables

<%
Dim name
For each name In Request.ServerVariables
      Response.Write "<p><b>" & name & ":</b>" &_
      Request.ServerVariables(name)
Next
%>

Alternate color of row
<%
Dim counter;
counter = counter + 1
Response.Write "<tr bgcolor=' "    ' alternate color of row
if (counter mod 2)<>0 then
   Response.Write "#efefef"        ' light grey color
else
   Response.Write "#dddddd"     ' medium grey color
end if
Response.Write " '>"
Response.Write "<td>" & data & "</td>"
Response.Write "</tr>"
%>

Logout page after Timeout
In a gobal.asa...
SUB Session_OnStart
Session.Timeout = 10   (10=minutes, below 602=seconds)

In the header  (<!-- includes#... --> on each page)...
<meta http-equiv=Refresh content="602; URL=logoff.asp">  (...after 10 minutes & 2 seconds goes to logoff)

Passing a Variable from one page to another...
First page: <a href="pagename.asp?ID=<%=rsRecs.Fields("someID")%>&Variable=<%=rsRecs.Fields("someVariable")%>"
onmouseover="window.status='Click to...';return true" onmouseout="window.status='';return true">somelink</a>
Second page: address string appears as: http://...pagename.asp?ID=123&Variable=XYZ
<% Dim ID, Variable
ID = Request.QueryString("ID")
Variable = Request.QueryString("Variable")
strSQL = "SELECT * FROM tablename WHERE someID = " & ID
%>

Connect="Provider=SQLOLEDB;Data Source=servername;Database=dbname;User ID=usersid;Password=***;"


"cbool", "CBool" "cbyte", "CByte" "ccur", "CCur" "cdate", "CDate" "cdbl", "CDbl" "cint", "CInt" "clng", "CLng" "csng", "CSng" "cstr", "CStr"

Other links about ASP & VBScript codes:   ASP 101 ,   ASP ,   Webmonkey ASP ,   VBScript Sample to SQL  and   ASP Resource Channel