1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

I want script for form validation on same page before page submit

Discussion in 'JavaScript' started by seovirus, Aug 26, 2009.

  1. #1
    I want script for form validation on same page before page submit
     
    seovirus, Aug 26, 2009 IP
  2. prasanthmj

    prasanthmj Member

    Messages:
    62
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    45
    #2
    try livevalidation dot com
     
    prasanthmj, Aug 27, 2009 IP
  3. gumape

    gumape Peon

    Messages:
    30
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Try this sample code, i think it helps you:

    <head>
    	<script>
    		function CheckAndSubmit () {
    			var userName = document.getElementById ("userName");
    			if (userName.value.length < 3) {
    				alert ("The name of the user must be at least 3 characters long!");
    				return false;
    			}
    
    			var password = document.getElementById ("password");
    			var repassword = document.getElementById ("repassword");
    			if (password.value.length < 6) {
    				alert ("The password must be at least 6 characters long!");
    				return false;
    			}
    			if (repassword.value != password.value) {
    				alert ("The two passwords are different!");
    				return false;
    			}
    
    			var acceptAgreement = document.getElementById ("acceptAgreement");
    			if (!acceptAgreement.checked) {
    				alert ("You must accept the User Agreement to register!");
    				return false;
    			}
    
    			return true;
    		}
    	</script>
    </head>
    <body>
    	<form id="regForm" method="post" action="#URL#" onsubmit="return CheckAndSubmit ()">
    		User Name: <input type="text" name="userName" id="userName" />
    		<br />
    		Password: <input type="password" name="password" id="password" />
    		<br />
    		Repeat Password: <input type="password" name="repassword" id="repassword" />
    		<br /><br />
    		<input type="checkbox" name="acceptAgreement" id="acceptAgreement" /> 
    		<label for="acceptAgreement">I accept the User Agreement and Privacy Policy</label>
    		<br /><br />
    		<input type="submit" value="Register" />
    	</form>
    </body>
    Code (markup):
     
    gumape, Sep 7, 2009 IP
  4. codventure

    codventure Guest

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Which type of validation do you want? There are so many validation in form fields like Name, Date, Mail, URL, Pincode, Telephone number, Do not blank..
    If you really want to do then read Javascript Expression language...
     
    codventure, Sep 8, 2009 IP