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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple checkbox select

Status
Not open for further replies.

bigben

Programmer
Oct 8, 2001
25
RO
Hi there,

I have an asp page that generates a list of 100s of checkboxes dynamically. All the checkboxes can have the same name or ID but have different values. I then want to have a button that I can click that will automatically check all the check boxes. Is there an easy way to do this using client side vbScript or do I need to reload the page and use server side script?

Thanks in advance...
 
<input type=button onClick=&quot;checkAll()&quot; value=&quot;Check All&quot;>

<script language=&quot;javascript&quot;>
function checkAll(){
allInputs = document.getElementsByTagName(&quot;input&quot;)
for (x=0; x< allInputs.length; x++){
if (allInputs[x].type == &quot;checkbox&quot;){
allInputs[x].checked = true
}
}
}
</script>

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

fart.gif
 
Thanks very much mwolf00. I will try this out, thanks for your help.
 
I also managed to work out a vbscript routine below where the checkbox name is &quot;chkCandidate&quot; and is initiated by a button called cmdSelectAll:

Sub cmdSelectAll_OnClick
For i=1 to form1.elements.length - 1
if form1.elements(i).name = &quot;chkCandidate&quot; then
form1.elements(i).checked = true
end if
next
End Sub

:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top