jQuery – Submit Form from JavaScript function and make fields translucent

Rather than having a submit button on the form, the conventional way is to have a button validate the input data followed by submission. Here’s how easy jQuery form submission is inside the validation function. The 3 lines of code above the submit button are to make the page translucent. My goal was to make the fields disabled too, but somehow the data wasn’t submitted correctly to server in that case. So I just made the button disabled.

function validateForm() {
   $ ( 'body' ).fadeIn('slow'); $ ( 'body' ).css({"opacity": "0.7"});
   $( 'button' ).prop('disabled', 'disabled');
   return $( "form" )[ 0 ].submit({url: '', type: 'post'});

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s