Checkbox

Selecting all contents in the checkbox

Page 1 of 1

1 Replies - 3351 Views - Last Post: 06 April 2003 - 07:19 AM Rate Topic: -----

#1 NuLLiFy   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 39
  • Joined: 25-March 03

Checkbox

Posted 06 April 2003 - 06:40 AM

I am currently doing an assignment for my web applications developement module. I am using ASP with vbscript. My problem is that I do not know how to make use of a button to select all the options in the checkbox.
I have a button called "Select All". Then if I clicked that, the five checkboxes in my web page should be selected. Should it be a client side or server side code? Please help me.
Is This A Good Question/Topic? 0
  • +

Replies To: Checkbox

#2 Amadeus   User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 250
  • View blog
  • Posts: 13,507
  • Joined: 12-July 02

Re: Checkbox

Posted 06 April 2003 - 07:19 AM

You can use either client side or server side scripting for this, but client side is nice and easy.
<script language=Javascript>
function checkAll(){
   document.testForm1.check1.checked = true;
   document.testForm1.check2.checked = true;
   document.testForm1.check3.checked = true;
}
function unCheckAll(){
   document.testForm1.check1.checked = false;
   document.testForm1.check2.checked = false;
   document.testForm1.check3.checked = false;
}
</script>


the functions above will work for checkboxes of different names
<script language=Javascript>
function checkAll(){
   document.testForm1.check1[0].checked = true;
   document.testForm1.check1[1].checked = true;
   document.testForm1.check1[2].checked = true;
}
function unCheckAll(){
   document.testForm1.check1[0].checked = false;
   document.testForm1.check1[1].checked = false;
   document.testForm1.check1[2].checked = false;
}
</script>


The above code will work if all the checkboxes have the same name (check1 in this case). The functions can be called in the following manner.
[CODE]
<input type="button" name="button1" value="Select all" onclick="checkAll();">
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1