Asked 7 years ago
24 Aug 2016
Views 5675
sarah

sarah posted

jQuery form submit not working , why ?

Hi

i am using following form

 <form action="demo_form.asp" id="name" method="get">
  First name: <input type="text" name="fname"><br>
  Last name: <input type="text" name="lname"><br>
	  <button id="submit" name="submit" type="button" >Save</button>
 
</form>
 


js code as below



$("#submit").on('click',function(){
		
$(this).closest('form').submit();
});


but on click of the save button . nothing is happening . i want to submit form on click of the save.
dilip

dilip
answered Nov 30 '-1 00:00

i think this will work for you . but there is many other way we can do submit form by click event of button


$("#submit").on('click',function(){
		
$(this).attr('type','submit').trigger('click');

});
jaggy

jaggy
answered Nov 30 '-1 00:00


1 .Suppose we have form with id "form1" and it contain the button type button with id submit than following code will help :


$("#submit").on('click',function(){
		
$("#form1").submit()

});


2. or Try to use type submit for the button instead of the type button

<button id="submit" name="submit" type="submit" >Save</button>

 

instead of

<button id="submit" name="submit" type="button" >Save</button>


i know second one is silly , lol
Post Answer