|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
|
|
#1
|
|||
|
|||
|
Access chechbox array...
Hi,
Please have a look at this code... Code:
<html>
<head>
<script lang='JavaScript'>
function toggleTick(count)
{
if (document.former.cbx_foo[count].checked == true)
document.former.cbx_foo[count].checked = false;
else
document.former.cbx_foo[count].checked = true;
}
function checkAll(count)
{
for (var j = 1; j <= count; j++)
{
if (document.former.cbx_foo[count].checked == false) document.former.cbx_foo[count].checked = true;
}
}
</script>
</head>
<body>
<form name="former">
<input type='checkbox' name='cbx_foo[]' value='0'><a href="#" onmouseover=toggleTick(0)>Text</a>
<br>
<input type='checkbox' name='cbx_foo[]' value='0'><a href="#" onmouseover=toggleTick(1)>Text</a>
<br>
<input type='checkbox' name='cbx_foo[]' value='0'><a href="#" onmouseover=toggleTick(2)>Text</a>
<br>
<input type="button" value="Check All" onClick="checkAll(3)">
</form>
</body>
</html>
The lines where i try to access any checkbox (e.g. document.former.cbx_foo[count].checked) are giving errors. Can someone help me with the correct line? For this reason niether the toggleTick nor the checkAll function is working properly. Thanks |
|
#2
|
||||
|
||||
|
checkboxes
You're close.
Although checkboxes are an array, the names are not. Remove the [] from the names and the first function will work. The second function has a few problems. It's OK to pass "count" to it and use that to limit the for loop incrementing. Arrays start at "0" not 1, change this to 0 if you want the first checkbox to be included in the "check all". The less "than or equal to" will increment to the "count" value. This is 1 more than the index values of the checkbox array, because they start at 0. Lastly, you should use the incrementing value "j" to id the checkboxes inside the loop, not "count". Last edited by Mittineague : June 2nd, 2006 at 09:04 PM. |
|
#3
|
|||
|
|||
|
Code:
Although checkboxes are an array, the names are not. Remove the [] from the names and the first function will work. No need. JavaScript doesn't recognize the names as an array, so you have to modify your code accordingly. Change all instances of Code:
document.former.cbx_foo[count].checked Code:
document.former.elements['cbx_foo[]'][count].checked |
|
#4
|
|||
|
|||
|
hey
Kravvitz is right but u can use this thig one more way Code:
var oChks= document.getElementsByName("CheckBoxName")
for(i=0;i<oChks.length;i++)
{
if(oChks[i].checked==true)
{
// do what ever you want
}
}
but before using these thing learn the diffrence between NAME and ID (not only these two but the very basics of HTML, i hope you know but know it with javascript). it will give you great help in developing thing and will giveyou good understanding of javascript, |
![]() |
| Viewing: Dev Articles Community Forums > Programming > JavaScript Development > Access chechbox array... |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|