
May 15th, 2007, 12:06 PM
|
|
Contributing User
|
|
Join Date: Oct 2002
Location: India
Posts: 64
Time spent in forums: 10 h 44 m 17 sec
Reputation Power: 6
|
|
|
Check and Uncheck...
Hi,
I am using this script which will check and uncheck all checkboxes for me on just one click.
Code:
<html>
<head>
<script language="javascript">
function checkall()
{
var dels = document.deleteform['todeletelist[]'];
for (var i = 0; i < dels.length; i++)
{
dels[i].checked = true;
}
}
function uncheckall()
{
var dels = document.deleteform['todeletelist[]'];
for (var i = 0; i < dels.length; i++)
{
dels[i].checked = false;
}
}
</script>
</head>
<body>
<a onClick="checkall();">Select All</a>
<a onClick="uncheckall();">None</a>
<form name="deleteform">
<input type="checkbox" name="todeletelist[]" value="1" />
<input type="checkbox" name="todeletelist[]" value="2" />
<input type="checkbox" name="todeletelist[]" value="3"/>
</form>
</body>
</html>
Here is all the code related to the same. I am generating all these checkboxes dynamically.
- It works OK, till i try to check or uncheck all checkboxes when there is just one checkbox in the todeletelist[]. You could just delete two checkboxes out of the three on top and check again.
- Is there anyway i can pass 'todeletelist[]' (or the name of the array) as a param to both the methods (checkall and uncheckall)?
Any solutions for these?
Thanks
Neville
|