Forums / Developer / JavaScript check all check box in form

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.

eZ debug

Timing: Jan 18 2025 04:15:11
Script start
Timing: Jan 18 2025 04:15:11
Module start 'content'
Timing: Jan 18 2025 04:15:12
Module end 'content'
Timing: Jan 18 2025 04:15:13
Script end

Main resources:

Total runtime1.1711 sec
Peak memory usage4,096.0000 KB
Database Queries212

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0072 588.9453180.8281
Module start 'content' 0.00721.0203 769.7734719.3516
Module end 'content' 1.02750.1436 1,489.1250340.4609
Script end 1.1711  1,829.5859 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00490.4172210.0002
Check MTime0.00170.1463210.0001
Mysql Total
Database connection0.00150.129310.0015
Mysqli_queries1.075491.82462120.0051
Looping result0.00250.21372100.0000
Template Total1.132596.720.5663
Template load0.00280.236720.0014
Template processing1.129796.464520.5649
Template load and register function0.00020.015510.0002
states
state_id_array0.00150.128610.0015
state_identifier_array0.00290.245020.0014
Override
Cache load0.00250.2143690.0000
Sytem overhead
Fetch class attribute can translate value0.00170.147560.0003
Fetch class attribute name0.00210.1807100.0002
XML
Image XML parsing0.00210.180960.0004
class_abstraction
Instantiating content class attribute0.00000.0017100.0000
General
dbfile0.00230.1942400.0001
String conversion0.00000.000530.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

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
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 35
 Number of unique templates used: 7

Time used to render debug report: 0.0002 secs