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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.