jQuery submit form with click event with new action

overflow picture overflow · Aug 31, 2013 · Viewed 62.3k times · Source

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.

Answer

commit picture commit · Aug 31, 2013

Give id to button and try this

$('#downloadButton').click(function(){
  $('form[name=test]').attr('action','test/test_new.xls');
  $('form[name=test]').submit();
});