Click here to Skip to main content
Rate this: bad
good
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 13-Jul-13 0:53am
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 at 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 at 13-Jul-13 8:06am
   
Not working!!!
dholakiyaankit at 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
0 Maciej Los 295
1 OriginalGriff 273
2 Aajmot Sk 234
3 Marcin Kozub 205
4 Richard MacCutchan 200
0 OriginalGriff 7,903
1 Sergey Alexandrovich Kryukov 7,127
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,820


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 13 Jul 2013
Copyright © CodeProject, 1999-2014
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