• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 75
  • Last Modified:

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

0
romsom
Asked:
romsom
  • 2
1 Solution
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
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
 
romsomAuthor Commented:
It's perfect, thank you very much!
Nice to hear from you again!
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
my pleasure, glad to help :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now