JavaScript check all check box in form

Author Message

piyawat mahawan

Monday 07 July 2008 2:59:45 am

JavaScript check all check box in form

Do you have a problem to check all check box is very more? This script I think it is ok .what do you think.?
Hear the JavaScript code

Example

<script language="javascript">
function check_all(){
NumChkBox=document.form_check.checkbox.length;

if(document.getElementById('check_all_box').checked==true){
for(i=1;i<=NumChkBox;i++){
NameChekBox="checkbox"+i;
document.getElementById("checkbox"+i).checked=true;
}

}else if(document.getElementById('check_all_box').checked==false){
for(i=1;i<=NumChkBox;i++){
NameChekBox="checkbox"+i;
document.getElementById("checkbox"+i).checked=false;
}

}
}
</script>

Hear the HTML code

Example

<body>
<form id="form1" name="form_check" method="post" action="">
<input type="checkbox" name="checkbox" id="checkbox1" value="checkbox" /> check box1<br>
<input type="checkbox" name="checkbox" id="checkbox2" value="checkbox" /> check box2<br>
<input type="checkbox" name="checkbox" id="checkbox3" value="checkbox" /> check box3<br>
<input type="checkbox" name="checkbox" id="checkbox4" value="checkbox" /> check box4<br>
<input type="checkbox" name="checkbox" id="checkbox5" value="checkbox" /> check box5<br>
<input type="checkbox" name="checkbox" id="checkbox6" value="checkbox" /> check box6<br>
<input type="checkbox" name="checkbox" id="checkbox7" value="checkbox" /> check box7
</form>
<input type="checkbox" name="check_all_box" id="check_all_box" onclick="check_all()" value="checkbox" />
<b>check all box</b>
</body>

Michael Scofield

Monday 07 July 2008 11:09:58 pm

Try this one:


<script>

function check_all() {
   // gets Instance to the Form
   this.form = document.getElementById('form1');
   
   // verifies if the instance was successfully obtained
   if (this.form) {
   
      // gets the current check state
      this.newCheckedValue = document.getElementById('check_all_box').checked;
	  

      // gets instace array for all input elements of the form
      this.checkboxNodes = this.form.getElementsByTagName('input');
	  
	  // loops the array
      for (this.i = 0; this.i < this.checkboxNodes.length; this.i++) {

          // verifies if the input element is a checkbox
          if (this.checkboxNodes[i].getAttribute('type') == 'checkbox') {
	   
	         // sets the new check value
             this.checkboxNodes[i].checked = this.newCheckedValue;
		  
		  }
		  
      }
	  
   }
}

</script>


<form id="form1" name="form_check" method="post" action="">
<input type="checkbox" name="checkbox" id="checkbox1" value="checkbox" /> check box1<br>
<input type="checkbox" name="checkbox" id="checkbox2" value="checkbox" /> check box2<br>
<input type="checkbox" name="checkbox" id="checkbox3" value="checkbox" /> check box3<br>
<input type="checkbox" name="checkbox" id="checkbox4" value="checkbox" /> check box4<br>
<input type="checkbox" name="checkbox" id="checkbox5" value="checkbox" /> check box5<br>
<input type="checkbox" name="checkbox" id="checkbox6" value="checkbox" /> check box6<br>
<input type="checkbox" name="checkbox" id="checkbox7" value="checkbox" /> check box7
</form>
<input type="checkbox" name="check_all_box" id="check_all_box" onclick="check_all()" value="checkbox" /> 

Btw, I think you are posting in the wrong forum, this is Ez Publish forum!! ;-)

Michael Scofield

piyawat mahawan

Tuesday 08 July 2008 8:30:56 pm

sorry i want some body to guide .

Piotrek Karaƛ

Tuesday 08 July 2008 9:51:28 pm

Hi,

This seems to be strictly JavaScript-related problem. Even though eZ Publish uses a number of technologies and standards, you're highly unlikely to learn those here, you should be much better of seearching some JavaScript-dedicated communities or docs.

Cheers,
Piotrek

EDIT: Sorry, haven't noticed Michael's remark.

--
Company: mediaSELF Sp. z o.o., http://www.mediaself.pl
eZ references: http://ez.no/partners/worldwide_partners/mediaself
eZ certified developer: http://ez.no/certification/verify/272585
eZ blog: http://ez.ryba.eu

Bruce Morrison

Tuesday 08 July 2008 11:27:36 pm

Howdy

There is actually a javascript function included in eZ publish (at least the admin interface) that does this.

Check out design/standard/javascript/tools/ezjsselection.js

ezjs_toggleCheckboxes( document.children, 'DeleteIDArray[]' )

The first parameter is the form DOm object, the second the checkboxname.

cheers
Bruce

My Blog: http://www.stuffandcontent.com/
Follow me on twitter: http://twitter.com/brucemorrison
Consolidated eZ Publish Feed : http://friendfeed.com/rooms/ez-publish

Pascal Specht

Wednesday 09 July 2008 7:59:35 am

Slightly off-topic, but very handy when it comes to check a lot of checkboxes in the backend (for example when deleting content): the CheckFox extention for Firefox: it allows to quickly check all checkboxes within the selected area...

</Pascal>

piyawat mahawan

Wednesday 09 July 2008 8:38:02 pm

thank you for us some kindly.

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 11:18:52
Script start
Timing: Jan 18 2025 11:18:52
Module start 'layout'
Timing: Jan 18 2025 11:18:52
Module start 'content'
Timing: Jan 18 2025 11:18:53
Module end 'content'
Timing: Jan 18 2025 11:18:53
Script end

Main resources:

Total runtime0.9940 sec
Peak memory usage4,096.0000 KB
Database Queries75

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0054 589.1641152.6406
Module start 'layout' 0.00540.0030 741.804739.4609
Module start 'content' 0.00840.9844 781.2656714.2578
Module end 'content' 0.99280.0012 1,495.523420.1563
Script end 0.9940  1,515.6797 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00380.3870160.0002
Check MTime0.00170.1739160.0001
Mysql Total
Database connection0.00050.047510.0005
Mysqli_queries0.916592.2034750.0122
Looping result0.00080.0800730.0000
Template Total0.962996.920.4814
Template load0.00240.246420.0012
Template processing0.960496.616920.4802
Template load and register function0.00020.021510.0002
states
state_id_array0.00090.094810.0009
state_identifier_array0.00060.063220.0003
Override
Cache load0.00220.2240690.0000
Sytem overhead
Fetch class attribute can translate value0.00100.098750.0002
Fetch class attribute name0.00110.1146100.0001
XML
Image XML parsing0.00180.181150.0004
class_abstraction
Instantiating content class attribute0.00000.0019100.0000
General
dbfile0.00100.1009290.0000
String conversion0.00000.001040.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
7content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
15content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
6content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
2content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
3content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 35
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs