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.
<html>
<head>
<title>For Each Text</title>
<script language="vbscript">
Function EditNonEmpty(ByVal strVal)
EditNonEmpty = Trim(strVal) = ""
End Function
Function EditNumeric(ByVal strVal)
EditNumeric = Trim(strVal) = "" Or Not IsNumeric(Trim(strVal))
End Function
Sub ResetForm(blnErase)
Dim txtElem
' Clear all <input type="text"> form elements.
For Each txtElem In frmDemo.all.tags("input")
If txtElem.type = "text" Then
If blnErase Then
txtElem.value = ""
End If
txtElem.style.backgroundColor = ""
End If
Next
End Sub
Sub btnSubmit_onclick()
Dim txtElem, obj1stErr
ResetForm False
' Validate multiple id="txtNonEmpty" form elements.
For Each txtElem In frmDemo.txtNonEmpty
If EditNonEmpty(txtElem.value) Then
txtElem.style.backgroundColor = "#ffcccc"
If Not IsObject(obj1stErr) Then Set obj1stErr = txtElem
End If
Next
' Validate single id="txtNumeric" form element.
If EditNumeric(frmDemo.txtNumeric.value) Then
frmDemo.txtNumeric.style.backgroundColor = "#ffcccc"
If Not IsObject(obj1stErr) Then Set obj1stErr = frmDemo.txtNumeric
End If
If IsObject(obj1stErr) Then
divMessage.innerText = "Oops, fill things in correctly please!"
obj1stErr.focus
Set obj1stErr = Nothing
Else
divMessage.innerText = ""
ResetForm True
frmDemo.txtNonEmpty(0).focus
End If
End Sub
Sub window_onload()
' Set focus to 1st field. Since there are multiple elements with
' the same id value, we have a collection and must index the
' one we want.
frmDemo.txtNonEmpty(0).focus
End Sub
</script>
</head>
<body>
<form name="frmDemo" id="frmDemo">
<table border="0" width="400">
<tr>
<td align="right">First Name</td>
<td><input type="text" name="FirstName" id="txtNonEmpty"
tabindex="1" size="15" maxlength="15"></td>
</tr>
<tr>
<td align="right">Last Name</td>
<td><input type="text" name="LastName" id="txtNonEmpty"
tabindex="2" size="15" maxlength="15"></td>
</tr>
<tr>
<td align="right">Address 1</td>
<td><input type="text" name="Address1" id="txtNonEmpty"
tabindex="3" size="30" maxlength="30"></td>
</tr>
<tr>
<td align="right">Address 2</td>
<td><input type="text" name="Address2"
tabindex="4" size="30" maxlength="30"></td>
</tr>
<tr>
<td align="right">City</td>
<td>
<input type="text" name="City" id="txtNonEmpty"
tabindex="5" size="15" maxlength="15">
State <input type="text" name="State" id="txtNonEmpty"
tabindex="6" size="2" maxlength="2">
Zip <input type="text" name="Zip" id="txtNumeric"
tabindex="7" size="5" maxlength="5">
</td>
</tr>
<tr>
<td align="right"><input type="button" id="btnSubmit" value="Submit"
tabindex="8"></td>
<td><div id="divMessage"
style="color:red; font: bold 12pt Arial"></div></td>
</tr>
</table>
</form>
</body>
</html>