JavaScript validation, Classic ASP

Hi Experts,
I'm updating the records where the checkbox is selected. It is working fine when users select at least one checkbox. But when they don't select anything, I get this error message:
Microsoft OLE DB Provider for SQL Server error '80040e14'
Incorrect syntax near ')'.
How could I add validation to my JavaScript to avoid this error message and remind users to select at least one checkbox.
This is my code:

<html>
<head>
<title>Edit</title>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function checkLikeMe($) {
    var x = document.getElementsByName('ID');
    for (var y = 0; y < x.length; y++)
        x[y].checked = $;
}

// End -->
</script>
<script type="text/javascript">
<!--
function validate_form ( )
{
	valid = true;
        if ( document.contact_form.DestQueueId.selectedIndex == 0 )
        {
                alert ( "Please select environment." );
                valid = false;
        }
        return valid;
}
//-->
</script>
</head>
<body>

<form name="contact_form" method="post" action="Recall_send.asp" onSubmit="return validate_form ( );">
<table class="border" align="center" cellpadding="0" cellspacing="0" width="500">
<tr>
<th>OU</th>

<th><input type="checkbox" onClick="checkLikeMe(this.checked)"></th>

</tr>
<%
rs.AbsolutePage = intPage
For intRecord = 1 To rs.PageSize
%>
<tr>
<td><%=rs("OU")%></td>
<td><input type="checkbox" name="ID" value="<%=rs("ID") %>"></td>
</tr>
<%
	rs.MoveNext
If rs.EOF Then Exit For
Next
rs.Close
set rs = Nothing
AdoCon.Close
set AdoCon = nothing
%>
</table>
<center>
<br />
<select name="DestQueueId">
<option value="">Change Environment:</option>
<option value="4">Stage</option>
<option value="5">Dev</option>
</select>

<input type="hidden" name="Pipa" value="on">

<input type="Submit" name="Submit" value="Submit" />
</center>
</form>

</body>
</html>

Open in new window

romsomIT DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Big MontyWeb Ninja at largeCommented:
this should work:

function validate_form ( )
{
	valid = true;
        if ( document.contact_form.DestQueueId.selectedIndex == 0 )
        {
                alert ( "Please select environment." );
                valid = false;
        }

        var x = document.getElementsByName('ID');
        var isChecked = false;
        for (var y = 0; y < x.length; y++) {
              if ( ! isChecked && x[ y ].checked )
                   isChecked = true;
         }

         if( ! isChecked ) {
                alert ( "Please select at least one record." );
                valid = false;
         }

        return valid;
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
romsomIT DeveloperAuthor Commented:
It's perfect, thank you very much!
Nice to hear from you again!
0
Big MontyWeb Ninja at largeCommented:
my pleasure, glad to help :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.