I have a form with a drop down and a number of checkboxes.
The drop down simply has numbers 1 to 5 in it.
The checkboxes are created by asp and there can be any number of them depending on the database. The checkboxes are named 'item' & the number of check box so for example the first checkbox would be called item1 and the nth checkbox would be called itemn.
Here is an example of the form:
<form action="newhomepageadminupdate.asp" method="post">
<SELECT NAME="numoflate">
<OPTION VALUE="1">1</OPTION>
<OPTION VALUE="2">2</OPTION>
<OPTION VALUE="3">3</OPTION>
<OPTION VALUE="4">4</OPTION>
<OPTION VALUE="5">5</OPTION>
</SELECT>
<% response.write("<input type='checkbox' name='item"&itemnumber&"' value='"&getitemsRS("ID"
&"'>"
%>
<% response.write("<input type='hidden' name='itemnumber' value='"&itemnumber&"'>"
%>
<input type="submit" value="make changes" onclick="return Validate(this.form)">
</form>
The asp simply adds in the numbers from the database (obtained somewhere else in the script)
I have a javascript function that must validate the form when someone submits it. The only validation criteria is that the number of checkboxes checked by the user must be the same amount they selected in the dropdown list.
i currently have something similar to this:
<script>
<!--//
function Validate(theForm)
{
var checknum = theForm.itemnumber.value;
var howmany = theForm.numoflate.value;
var itemchecked = 0;
for (i = 0; i < checknum; i++)
{
if (theForm.item+i.checked)
itemchecked += 1;
}
if (itemchecked != howmany)
{
alert("You must check the same amout of boxes as you have selected in the dropdown menu!"
;
return false;
}
else
return true;
}
//-->
</script>
As you can see from the highlighted red text i am having difficulty finding out if the dynamicaly named checkboxes are checked by the user.
Can someone tell me how to use two variables to get a name of a check box or offer a better solution to this problem?
The validation must be performed client side when the form is submitted
thanks in advance
The drop down simply has numbers 1 to 5 in it.
The checkboxes are created by asp and there can be any number of them depending on the database. The checkboxes are named 'item' & the number of check box so for example the first checkbox would be called item1 and the nth checkbox would be called itemn.
Here is an example of the form:
<form action="newhomepageadminupdate.asp" method="post">
<SELECT NAME="numoflate">
<OPTION VALUE="1">1</OPTION>
<OPTION VALUE="2">2</OPTION>
<OPTION VALUE="3">3</OPTION>
<OPTION VALUE="4">4</OPTION>
<OPTION VALUE="5">5</OPTION>
</SELECT>
<% response.write("<input type='checkbox' name='item"&itemnumber&"' value='"&getitemsRS("ID"


<% response.write("<input type='hidden' name='itemnumber' value='"&itemnumber&"'>"

<input type="submit" value="make changes" onclick="return Validate(this.form)">
</form>
The asp simply adds in the numbers from the database (obtained somewhere else in the script)
I have a javascript function that must validate the form when someone submits it. The only validation criteria is that the number of checkboxes checked by the user must be the same amount they selected in the dropdown list.
i currently have something similar to this:
<script>
<!--//
function Validate(theForm)
{
var checknum = theForm.itemnumber.value;
var howmany = theForm.numoflate.value;
var itemchecked = 0;
for (i = 0; i < checknum; i++)
{
if (theForm.item+i.checked)
itemchecked += 1;
}
if (itemchecked != howmany)
{
alert("You must check the same amout of boxes as you have selected in the dropdown menu!"

return false;
}
else
return true;
}
//-->
</script>
As you can see from the highlighted red text i am having difficulty finding out if the dynamicaly named checkboxes are checked by the user.
Can someone tell me how to use two variables to get a name of a check box or offer a better solution to this problem?
The validation must be performed client side when the form is submitted
thanks in advance