mubarakabbas Posted January 5, 2010 Share Posted January 5, 2010 Hi, i want the form with check all and Uncheck all, javascript is not working <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <SCRIPT LANGUAGE="JavaScript"> <!-- <!-- Begin function CheckAll(check_list) { for (i = 0; i < check_list.length; i++) check_list.checked = true ; } function UnCheckAll(check_list) { for (i = 0; i < check_list.length; i++) check_list.checked = false ; } // End --> </script> </head> <body> <?php if(isset($_POST[chk])) { for($i=0;$i<5;$i++) { echo $_POST['check_list'][$i]; } echo "hi"; exit(); } ?> This is the HTML code to be kept inside the body tag. <form name="myform" action="check.php" method="post"> <b>Scripts for Web design and programming</b><br> <input type="checkbox" name="check_list[]" value="1">ASP<br> <input type="checkbox" name="check_list[]" value="2">PHP<br> <input type="checkbox" name="check_list[]" value="3">JavaScript<br> <input type="checkbox" name="check_list[]" value="4">HTML<br> <input type="checkbox" name="check_list[]" value="5">MySQL<br> <input type="button" name="Check_All" value="Check All" onClick="CheckAll(document.myform.check_list)"> <input type="button" name="Un_CheckAll" value="Uncheck All" onClick="UnCheckAll(document.myform.check_list)"> <input type="submit" name="chk" value="CHK" /> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/187239-help-me-may-be-silly-for-you/ Share on other sites More sharing options...
oni-kun Posted January 5, 2010 Share Posted January 5, 2010 If this is a javascript question than ask in the javascript forum! And I'm sure there are many tuts online for this.... Quote Link to comment https://forums.phpfreaks.com/topic/187239-help-me-may-be-silly-for-you/#findComment-988773 Share on other sites More sharing options...
rajivgonsalves Posted January 5, 2010 Share Posted January 5, 2010 not perfect but I guess it should give you an idea <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <SCRIPT LANGUAGE="JavaScript"> <!-- <!-- Begin function CheckAll(form, name) { for (var i=0;i<form.elements.length;i++) { var e = form.elements[i]; if (e.type=='checkbox' && e.name.indexOf(name) == 0 && !e.disabled) { e.checked = true; } } } function UnCheckAll(form, name) { for (var i=0;i<form.elements.length;i++) { var e = form.elements[i]; if (e.type=='checkbox' && e.name.indexOf(name) == 0 && !e.disabled) { e.checked = false; } } } // End --> </script> </head> <body> <?php if(isset($_POST[chk])) { for($i=0;$i<5;$i++) { echo $_POST['check_list'][$i]; } echo "hi"; exit(); } ?> This is the HTML code to be kept inside the body tag. <form name="myform" action="check.php" method="post"> <b>Scripts for Web design and programming</b><br> <input type="checkbox" name="check_list[]" value="1">ASP<br> <input type="checkbox" name="check_list[]" value="2">PHP<br> <input type="checkbox" name="check_list[]" value="3">JavaScript<br> <input type="checkbox" name="check_list[]" value="4">HTML<br> <input type="checkbox" name="check_list[]" value="5">MySQL<br> <input type="button" name="Check_All" value="Check All" onClick="CheckAll(this.form, 'check_list')"> <input type="button" name="Un_CheckAll" value="Uncheck All" onClick="UnCheckAll(this.form, 'check_list')"> <input type="submit" name="chk" value="CHK" /> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/187239-help-me-may-be-silly-for-you/#findComment-988782 Share on other sites More sharing options...
mubarakabbas Posted January 5, 2010 Author Share Posted January 5, 2010 thank you brother for your hands, but still am not getting javascript write... if i remove the array_name[] parameter its working, not perfect but I guess it should give you an idea <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <SCRIPT LANGUAGE="JavaScript"> <!-- <!-- Begin function CheckAll(form, name) { for (var i=0;i<form.elements.length;i++) { var e = form.elements[i]; if (e.type=='checkbox' && e.name.indexOf(name) == 0 && !e.disabled) { e.checked = true; } } } function UnCheckAll(form, name) { for (var i=0;i<form.elements.length;i++) { var e = form.elements[i]; if (e.type=='checkbox' && e.name.indexOf(name) == 0 && !e.disabled) { e.checked = false; } } } // End --> </script> </head> <body> <?php if(isset($_POST[chk])) { for($i=0;$i<5;$i++) { echo $_POST['check_list'][$i]; } echo "hi"; exit(); } ?> This is the HTML code to be kept inside the body tag. <form name="myform" action="check.php" method="post"> <b>Scripts for Web design and programming</b><br> <input type="checkbox" name="check_list[]" value="1">ASP<br> <input type="checkbox" name="check_list[]" value="2">PHP<br> <input type="checkbox" name="check_list[]" value="3">JavaScript<br> <input type="checkbox" name="check_list[]" value="4">HTML<br> <input type="checkbox" name="check_list[]" value="5">MySQL<br> <input type="button" name="Check_All" value="Check All" onClick="CheckAll(this.form, 'check_list')"> <input type="button" name="Un_CheckAll" value="Uncheck All" onClick="UnCheckAll(this.form, 'check_list')"> <input type="submit" name="chk" value="CHK" /> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/187239-help-me-may-be-silly-for-you/#findComment-988791 Share on other sites More sharing options...
rajivgonsalves Posted January 5, 2010 Share Posted January 5, 2010 hmm.. which array_name[] parameter the code I provided works fine in FF not checked it in IE but it should give you an idea on how to traverse through the elements of the form. Quote Link to comment https://forums.phpfreaks.com/topic/187239-help-me-may-be-silly-for-you/#findComment-988794 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.