views:

192

answers:

5

Hi I want to submit a form without using submit button how can i do that?

A: 

Through javascript you can call form.submit()

Duracell
+2  A: 

Using jQuery you can do this. Check this

http://net.tutsplus.com/tutorials/javascript-ajax/submit-a-form-without-page-refresh-using-jquery/

Prakash Kalakoti
What happens when the user has JavaScript disabled? accessibility issues!
Ben Rowe
In that case you need to think of some alternative approach like using the<noscript> tags to display a button which post back the complete page, but for this your actual button which do the form submit in the background should be constructed in the <script> tag.Or you can simpally show a message that "JS is disabled, so this page will not work"
Prakash Kalakoti
+1  A: 

Use javascript. Something like

document.forms["myform"].submit();

or

document.myform.submit();

You need to set the name (1. example) or id (2. example) attribute for your form to make this work.

tweber
A: 

Use jquery's form methods to serialize the form variables and send via ajax.

http://api.jquery.com/category/forms/

You can add some javascript logic to ANY submit methods by passing a function to the form's submit event handler.

Eg.

$('#my_form').submit(function(){
  alert('Handler for .submit() called.');
  return false;
});

Returning false blocks the form from being submitted by all other methods (including the "traditional" submit button). You'd put your ajax code before the return statement.

or add bind the submit function to ANY dom element (image,button,etc.) Eg.

$('#my_cool_image').click(function() {
  $('#my_form').submit();
});

See more at http://api.jquery.com/submit/

Good Luck

Homer6