Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loop through Form elements via VBScript 1

Status
Not open for further replies.

GoTerps88

Programmer
Apr 30, 2007
174
US
I want to be able to loop through form elements of type checkbox on form. How would I accomplish this in VBScript?

A sample would be great. I wasn't able to located on online.

Thanks...
 
I would suggest you take a look at Microsoft's HTAOmatic tool which among other things demonstrates how to create a checkbox and check its value.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
To:eek:p
This is how you do it (client-side).

[1] Suppose the form tag is of the bare structure like this.
[tt]
<form name="x" id="y" action="etc" method="etcetc">
<!-- field elements inside -->
</form>
[/tt]
[2] The handling and the reference to the form and field elements is done in a vbs function/sub (doesn't matter) like this.
[tt]
sub somehandler
dim oform,celem,i
set oform=document.forms("x")
[green]'or alternative
'set oform=document.getElementById("y")[/green]
set celem=oform.elements

for i=0 to celem.length
if celem(i).type="checkbox" then
msgbox "checkbox info" & vbcrlf & vbcrlf & _
"name: " & vbtab & vbtab & celem(i).name & vbcrlf & _
"id:" & vbtab & vbtab & celem(i).id & vbcrlf & _
"checked?:" & vbtab & vbtab & celem(i).checked & vbcrlf & _
"value:" & vbtab & vbtab & celem(i).value & vbcrlf & _
"outerHTML:" & vbtab & celem(i).outerHTML
[blue]'based on your criteria, you do thing about it hereon
'its reference is now found and is identified as celem(i)[/blue]
end if
next
set celem=nothing
set oform=nothing
end sub
[/tt]
ps The msgbox is just intended to show you what the handler has found. You can spare it and go directly for the real stuff to perform on the checkbox found.
 
Amendment
The corresponding line should sure be read line this.
[tt] for i=0 to celem.length [red]-1[/red][/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top