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>
<!-- saved from url=(0011)about:blank -->
<head>
<script language="VBScript">
'Notes:
' <br> elements' id values are not entered into a <form>'s
' namespace, but are always global to document.
'
' Element collections are created whenever two elements
' with the same id exist within a namespace scope, but as
' soon as only one element remains in the collection it is
' promoted to an element directly contained within the
' parent element.
'
' To tie parallel collections together it is useful to
' create an expando property containing the index of each
' element via setAttribute.
Option Explicit
Function Exists(ByVal ElementId)
Exists = Not (document.getElementById(ElementId) Is Nothing)
End Function
Function IsCollection(ByVal Element)
IsCollection = TypeName(Element) = "DispHTMLElementCollection"
End Function
Sub btnSet_onclick()
Dim intItem, strChoices, objNew
With frmData
If Exists("brFrmLine") Then
If IsCollection(brFrmLine) Then
For intItem = brFrmLine.length - 1 To 1 Step -1
.removeChild brFrmLine(intItem)
.removeChild .txtItem(intItem)
.removeChild .chkItem(intItem)
Next
End If
.removeChild brFrmLine
.removeChild .txtItem
.removeChild .chkItem
End If
strChoices = Trim(txtChoices.value)
If Len(strChoices) > 0 Then
strChoices = Split(strChoices, ",")
For intItem = 0 To UBound(strChoices)
Set objNew = document.createElement("input")
With objNew
.type = "checkbox"
.name = "check"
.id = "chkItem"
.setAttribute "assoc", intItem
.attachEvent "onclick", getRef("chkItem_onclick")
End With
.appendChild objNew
Set objNew = document.createElement("input")
With objNew
.type = "text"
.name = "text"
.id = "txtItem"
.value = Trim(strChoices(intItem))
End With
.appendChild objNew
Set objNew = document.createElement("br")
objNew.id = "brFrmLine"
.appendChild objNew
Next
End If
End With
End Sub
Sub chkItem_onclick()
Dim Obj, Color
Set Obj = window.event.srcElement
If Obj.checked then
Color = "pink"
Else
Color = "transparent"
End If
If IsCollection(frmData.txtItem) Then
frmData.txtItem(Obj.assoc).style.backgroundColor = Color
Else
frmData.txtItem.style.backgroundColor = Color
End If
End Sub
Sub window_onload()
Dim intItem
With frmData
If IsCollection(.chkItem) Then
For intItem = 0 To .chkItem.length - 1
With .chkItem(intItem)
.setAttribute "assoc", intItem
.attachEvent "onclick", getRef("chkItem_onclick")
End With
Next
End If
End With
End Sub
</script>
</head>
<body>
Enter a list of choices separated by commas:<br>
<input id="txtChoices" size="60" value="This, That, Another">
<br>
<button id="btnSet">Set</button>
<form name="data" id="frmData">
<input type="checkbox" name="check" id="chkItem">
<input type="text" name="text" id="txtItem" value="zero">
<br id="brFrmLine">
<input type="checkbox" name="check" id="chkItem">
<input type="text" name="text" id="txtItem" value="one">
<br id="brFrmLine">
</form>
</body>
</html>