0

I have a PHP page with simple script to "Check All" the checkboxes of the page.

I have to include a header.php in my code, and that is the area of problem.

When i don't include it, the code works fine. But when i include it code does not work, means CHECK ALL button does not selects all checkboxes.

My code is --

checkall.php

<html>
<body>
<script language="JavaScript">
function toggle(source) {
checkboxes = document.getElementsByName('foo');
for(var i=0, n=checkboxes.length;i<n;i++) {
checkboxes[i].checked = source.checked;
}
}
</script>
<?php include('header.php'); ?>

<input type="checkbox" onClick="toggle(this)" /> Toggle All<br/>

<input type="checkbox" name="foo" value="bar1"> Bar 1<br/>
<input type="checkbox" name="foo" value="bar2"> Bar 2<br/>
<input type="checkbox" name="foo" value="bar3"> Bar 3<br/>
<input type="checkbox" name="foo" value="bar4"> Bar 4<br/>
<?php include('footer.php'); ?>
</body>
</html>

I have tried all suggestions By Can Berk Güder in this Question.

Any Suggestions...???

Community
  • 1
  • 1
Gaurav Manral
  • 600
  • 4
  • 7
  • 24
  • any error in your browser console – Arun P Johny Oct 29 '13 at 06:01
  • if your code is working fine when header.php is not included then i guess u are overriding the function or the checkbox names or something. when a page is included in a page it will load as one single document. so some alterations are happening when ur including your header.php page. or your entire js is not working due to some error in other functions written or called in header.php – zamil Oct 29 '13 at 06:06
  • The only warning type msg is --- use of getpreventdefault() is deprecated – Gaurav Manral Oct 29 '13 at 06:06
  • I would start by isolating the output of header.php. its probably not closing some HTML tags or something that it outputs. It might even be overwriting the javascript function. Once you have fixed your HTML (if there are any problems) if you still have issues get Firebug for firefox or firebug lite for Internet explorer. If you are using chrome then even easier just press control+shift+i and then check the console tab. It should give you JavaScript errors. I think Safari has a built in dev tool kit aswell. – Daryl B Oct 29 '13 at 06:18
  • i understand, but i could not specify any error in that. I checked the page source of the HTML, and could not figure out any error. :( – Gaurav Manral Oct 29 '13 at 06:27
  • You are right Zamil and Daryl, i made my header.php blank, and the script started working. – Gaurav Manral Oct 29 '13 at 06:32
  • I got the error. It's in this SCRIPT --- when i delete this code, my page works fine. It is the same script where i am getting "use of getpreventdefault() is deprecated" error. – Gaurav Manral Oct 29 '13 at 06:40

1 Answers1

0

i do not know if it help or not but u just can try change the include to include_once

<html>
<body>
<script language="JavaScript">
function toggle(source) {
checkboxes = document.getElementsByName('foo');
for(var i=0, n=checkboxes.length;i<n;i++) {
checkboxes[i].checked = source.checked;
}
}
</script>
<?php  include_once 'header.php';  ?>

<input type="checkbox" onClick="toggle(this)" /> Toggle All<br/>

<input type="checkbox" name="foo" value="bar1"> Bar 1<br/>
<input type="checkbox" name="foo" value="bar2"> Bar 2<br/>
<input type="checkbox" name="foo" value="bar3"> Bar 3<br/>
<input type="checkbox" name="foo" value="bar4"> Bar 4<br/>
<?php  include_once 'footer.php';  ?>
</body>
</html>
airi
  • 653
  • 5
  • 11
  • i just test your code. seem working perfectly. maybe it is because you have two version of in one browser – airi Nov 26 '13 at 03:24