Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-13-2011, 04:33 PM   PM User | #1
juneaid
New to the CF scene

 
Join Date: Nov 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
juneaid is an unknown quantity at this point
Question JQuery Form Validation with onSubmit

Hello,

I am a newbee on web coding. I want to add a form with jquery validation to my php based website in order to stop the form until the jquery validation requirements are fulfilled.

After some search I have prepared the script as seen below.

Code:
<script src="{external file='js/jquery.validate.js'}" type="text/javascript"></script>
<script id="demo" type="text/javascript">

$(document).ready(function() {
	var validator = $("#registration_form").validate({
		rules: {
			firstname: "required",
                        },
		messages: {
			firstname: "Enter your firstname",
                        },
		errorPlacement: function(error, element) {
			if ( element.is(":radio") )
				error.appendTo( element.parent().next().next() );
			else if ( element.is(":checkbox") )
				error.appendTo ( element.next() );
			else
				error.appendTo( element.parent().next() );
		},
		submitHandler: function() {
			alert("submitted!");
		},
		success: function(label) {
			label.html("&nbsp;").addClass("checked");
		}
	});
	
});
</script>
The form starts with the following tag
Code:
<form id="registration_form" action="registration.php" onsubmit="return validate();" method="post">
I have found the way to use the "onsubmit" when I search on the internet, as below.

Code:
function Validate()
{
    if (document.exampleForm.chkBox.checked)
        return true;
    alert('You must check the box before submitting this form');
    return false;
}
However, I could not integrate the "function Validate()" to my script above.

Please can you advise me how I can handle with this situation?

Thanks.
juneaid is offline   Reply With Quote
Reply

Bookmarks

Tags
form validation, jquery, onsubmit

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:57 PM.


Advertisement
Log in to turn off these ads.