Click here to Skip to main content
12,395,378 members (71,401 online)
Rate this:
 
Please Sign up or sign in to vote.
script type="text/javascript">
<!--
// Form validation code will come here.
function validate() {

if (document.myForm.name.value == "") {
alert("Please provide your name!");
document.myForm.Name.focus();
return false;
}
if (document.myForm.Email.value == "")
{
alert("Please provide your Email!");
document.myForm.EMail.focus();
return false;
}


if (document.myForm.country.value == "")
{
alert("Please provide your country!");
return false;
}
return (true);
}
//-->
</script>

<form id="form1" name="form1" runat="server" onsubmit="return(validate());">

   
Name <input name="name" id="name" type="text" style="width:140px;" >
Email <input name="Email" id="Email" type="text" style="width:140px;" >
Phone Number <input name="Phoneno" id="Phoneno" type="text" style="width:140px;" >
Country <input name="country" id="country" type="text" style="width:140px;" >
Comments <textarea name="comments" style="width:140px;" rows="2" class="txtbox1" id="comments"></textarea>
  <asp:Button ID="Buttonsubmit" runat="server" Text="Submit Query"
onclick="Buttonsubmit_Click" />
</form>
Posted 12-Jul-13 23:53pm
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Check this


<asp:Button ID="Buttonsubmit" runat="server" Text="Submit Query"
onclick="Buttonsubmit_Click" onclientclick="validate()" /> 
  Permalink  
Comments
rranjansir 13-Jul-13 8:05am
   
Not working!!
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

<asp:Button ID="Buttonsubmit" runat="server" Text="Submit Query"
onclick="Buttonsubmit_Click" onclientclick="return validate()" />


also check your browser for javascript error if there is syntax error then this validation function will not be called
  Permalink  
Comments
rranjansir 13-Jul-13 8:06am
   
Not working!!!
dholakiyaankit 13-Jul-13 8:07am
   
debug your javascript

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 13 Jul 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100