Tuesday, July 29, 2008

Javascript select / deselect

Javascript code
function checkAll()
{
var field = document.getElementsByName('list[]');
for (i = 0; i < field.length; i++)
field[i].checked = true ;
}

function uncheckAll()
{
var field = document.getElementsByName('list[]');
for (i = 0; i < field.length; i++)
field[i].checked = false ;
}



PHP Code :
if ( isset($_POST['submit']) ) {
//print_r($_POST['list']);
$postCount = count($_POST['list']);

for ( $i=0; $i < $postCount; $i++ ) {

//$deleteIds .= $_POST['list'][$i].',';
echo $_POST['list'][$i]."
";

}
}

Sunday, July 27, 2008

Javascript Checkbox Select/Deselect All

<script language="JavaScript"><br /><!-- <!-- Begin function CheckAll(chk) { for (i = 0; i < checked =" true" i =" 0;" checked =" false"><br /></script>

This is the HTML code to be kept inside the body tag.

<form name="myform" action="checkboxes.asp" method="post">

<b>Scripts for Web design and programming</b>


<input name="check_list" value="1" type="checkbox">ASP


<input name="check_list" value="2" type="checkbox">PHP


<input name="check_list" value="3" type="checkbox">JavaScript


<input name="check_list" value="4" type="checkbox">HTML


<input name="check_list" value="5" type="checkbox">MySQL


<input name="Check_All" value="Check All" onclick="CheckAll(document.myform.check_list)" type="button">

<input name="Un_CheckAll" value="Uncheck All" onclick="UnCheckAll(document.myform.check_list)" type="button">


 


 


For PHP code to get check box's value

if ( isset($_POST['Submit']) ) {

$postCount = count($_POST['check_list']);

for ( $i=0; $i < $postCount; $i++ ) {

$deleteIds .= $_POST['check_list'][$i].',';

}</form>