Jump to content

checkbox


rashmi_k28

Recommended Posts

<SCRIPT LANGUAGE="JavaScript">

function CheckAll(chk)
{
for (i = 0; i < chk.length; i++)
chk[i].checked = true ;
}

function UnCheckAll(chk)
{
for (i = 0; i < chk.length; i++)
chk[i].checked = false ;
}
</script>

 

 

 

<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="checkbox" name="check_list[]" value="1">1

<input type="checkbox" name="check_list[]" value="2">2

<input type="checkbox" name="check_list[]" value="3">3

 

 

 

When I click on the CheckAll button, it doesnot check all the boxes.

 

If I use

 

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

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

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

 

This works.

 

 

How can I pass the multiple value in the array to another page

Link to comment
https://forums.phpfreaks.com/topic/128349-checkbox/
Share on other sites

It would be nice to see more of the code - especially how you are calling the function. Are you using 'checl_list' or 'check_list[]'? Because you have defined the names as array names, you can't referenence them in all the same ways. For example you CAN't use this:

document.forms[0].check_list[]

But you CAN use this

document.forms[0]['check_list[]']

 

You only need ONE function, just pass a bool value for the check state. Here's a revise function and a way to properly reference the check objects

 

<html>
<head>
<script type="text/javascript">

function CheckAll(chkObj, chkBool)
{
  for (i = 0; i < chkObj.length; i++)
  {
    chkObj[i].checked = chkBool;
  }
}

</script>

</head>

<body>
<form>
<input type="checkbox" name="check_list[]" value="1">1<br />
<input type="checkbox" name="check_list[]" value="2">2<br />
<input type="checkbox" name="check_list[]" value="3">3<br />
<br /><br />
<button onclick="CheckAll(document.forms[0]['check_list[]'], true)">Check All</button>
<button onclick="CheckAll(document.forms[0]['check_list[]'], false)">Check None</button>
</form>

</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/128349-checkbox/#findComment-665749
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.