I am fairly new to JS and was wondering how would I loop through checkboxes on a form and only check those where name is like _*_2_*_
For example, this checkbox name would be checked, _274_2_410_ but this one would not _274_3_410_
<html>
<head>
<title>Untitled Document</title>
</head>
<script>
function checkall()
{
for(i=0; i<document.Form1.elements.length; i++)
{
if(document.Form1.elements.type=="checkbox")
{
document.Form1.elements.checked=true;
}
}
}
</script>
<body>
<a href="#" onclick="checkall()">Check All</a>
<form action="" method="get" name="Form1">
<input id="_274_2_410_" type="checkbox" name="_274_2_410_" />
<input id="_275_2_410_" type="checkbox" name="_275_2_410_" />
<input id="_274_3_410_" type="checkbox" name="_274_3_410_" />
</form>
</body>
</html>
For example, this checkbox name would be checked, _274_2_410_ but this one would not _274_3_410_
<html>
<head>
<title>Untitled Document</title>
</head>
<script>
function checkall()
{
for(i=0; i<document.Form1.elements.length; i++)
{
if(document.Form1.elements.type=="checkbox")
{
document.Form1.elements.checked=true;
}
}
}
</script>
<body>
<a href="#" onclick="checkall()">Check All</a>
<form action="" method="get" name="Form1">
<input id="_274_2_410_" type="checkbox" name="_274_2_410_" />
<input id="_275_2_410_" type="checkbox" name="_275_2_410_" />
<input id="_274_3_410_" type="checkbox" name="_274_3_410_" />
</form>
</body>
</html>