Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery submit form with click event with new action

I am having a form like this

    <form name="test" action="test/test_new" />
<input type="text" />
<input type="submit" value="search"/>
<input type="button" value="download"/>

I need a click even for download button. Eg. If i click download it should submit as text/text_new.xls instead of text/text_new. How can i do it.

like image 231
Prabhakaran Avatar asked Aug 31 '13 05:08

Prabhakaran


People also ask

How do I submit a form on click event?

In javascript onclick event , you can use form. submit() method to submit form. You can perform submit action by, submit button, by clicking on hyperlink, button and image tag etc. You can also perform javascript form submission by form attributes like id, name, class, tag name as well.

How can we submit a form using jQuery?

Forms can be submitted either by clicking an explicit <input type="submit"> , <input type="image"> , or <button type="submit"> , or by pressing Enter when certain form elements have focus.

Which event is triggered when a form submit button is pressed?

The submit event fires when the user clicks a submit button ( <button> or <input type="submit">) or presses Enter while editing a field (e.g. <input type="text">) in a form. The event is not sent to the form when calling the form. submit() method directly.


1 Answers

Give id to button and try this

$('#downloadButton').click(function(){
  $('form[name=test]').attr('action','test/test_new.xls');
  $('form[name=test]').submit();
});
like image 198
commit Avatar answered Nov 09 '22 21:11

commit