ClueLess
09-17-2007, 06:16 PM
I am not sure this post should be in this forum or javascript...since it's asp and javascript so I post it here...
I’ve a list of checkboxes:
Grade 1, Grade 2, Grade 3, Grade 4, Grade 5, Grade 6....
I retrieve the values from the database: if it has a value then display a selected checkbox, if not display just a checkbox – depends on the condition.
The problem I’m having now is if I uncheck the selected checkbox(es) , hit submit button…it still lets me go through.
What I try to do is if I don’t select any checkbox(es) (or uncheck the selected checkbox) - then hit a Submit button.... the alert message will popup and should not let me submit it. How can we do that?
Thanks you very much for your help..
Below is the code I've tried:
<script type="text/javascript" language="JavaScript">
<!--
function checkCheckBoxes(formUpdate) {
if (
formUpdate.Grade1.checked == false &&
formUpdate.Grade2.checked == false &&
formUpdate.Grade3.checked == false &&
formUpdate.Grade4.checked == false &&
formUpdate.Grade5.checked == false &&
formUpdate.Grade6.checked == false &&
{
alert ('Please select one of the checkboxes');
return false;
} else {
return true;
}
}
//-->
</script>
</head>
<form name="formUpdate" action="Updated.asp" method="post" onsubmit="return checkCheckBoxes(formUpdate);">
<table>
<tr>
<%if RS("Grade") = "1" then %>
<td colspan="2">
<input type="checkbox" checked name="Grade1" value="cg">Grade 1
</td>
<%else %>
<td colspan="2">
<p><input type="checkbox" name=" Grade1" value="1"> Grade 1
</td>
<%end if %>
</tr>
<tr>
<%if RS("Grade") ="2" then %>
<td colspan="2">
<p><input type="checkbox" checked name="Grade2" value="cg">Grade 2
</td>
<%else %>
<td colspan="2">
<p><input type="checkbox" name="Grade2" value="2">Grade 2
</td>
<%end if %>
</tr>
…so on to Grade 6
<td valign="top"><p> </p></td>
<td valign="top">
<input type="submit" value="Submit" name="submit">
</td>
</tr>
</table>
</form>
I’ve a list of checkboxes:
Grade 1, Grade 2, Grade 3, Grade 4, Grade 5, Grade 6....
I retrieve the values from the database: if it has a value then display a selected checkbox, if not display just a checkbox – depends on the condition.
The problem I’m having now is if I uncheck the selected checkbox(es) , hit submit button…it still lets me go through.
What I try to do is if I don’t select any checkbox(es) (or uncheck the selected checkbox) - then hit a Submit button.... the alert message will popup and should not let me submit it. How can we do that?
Thanks you very much for your help..
Below is the code I've tried:
<script type="text/javascript" language="JavaScript">
<!--
function checkCheckBoxes(formUpdate) {
if (
formUpdate.Grade1.checked == false &&
formUpdate.Grade2.checked == false &&
formUpdate.Grade3.checked == false &&
formUpdate.Grade4.checked == false &&
formUpdate.Grade5.checked == false &&
formUpdate.Grade6.checked == false &&
{
alert ('Please select one of the checkboxes');
return false;
} else {
return true;
}
}
//-->
</script>
</head>
<form name="formUpdate" action="Updated.asp" method="post" onsubmit="return checkCheckBoxes(formUpdate);">
<table>
<tr>
<%if RS("Grade") = "1" then %>
<td colspan="2">
<input type="checkbox" checked name="Grade1" value="cg">Grade 1
</td>
<%else %>
<td colspan="2">
<p><input type="checkbox" name=" Grade1" value="1"> Grade 1
</td>
<%end if %>
</tr>
<tr>
<%if RS("Grade") ="2" then %>
<td colspan="2">
<p><input type="checkbox" checked name="Grade2" value="cg">Grade 2
</td>
<%else %>
<td colspan="2">
<p><input type="checkbox" name="Grade2" value="2">Grade 2
</td>
<%end if %>
</tr>
…so on to Grade 6
<td valign="top"><p> </p></td>
<td valign="top">
<input type="submit" value="Submit" name="submit">
</td>
</tr>
</table>
</form>