you can intercept a click on a button, read its data and change the form before sending:
So HTML:
<form id='double' method="GET" action="http://google.com/search"> <input name="q" type="text"> <button class="Submit" data-target=""> Submmit here</button> <button class="Submit" data-target="_blank"> Open new</button> </form>
Js
$('button.Submit').click( function() { var t=$(this); var form=t.parents('form'); form.attr('target',t.data('target')); form.submit(); return false; });
this way you can control the target parameter in your html markup.
http://jsfiddle.net/oceog/gArdk/
if you do not clear the target form, you will get the following script:
- the user clicks on the popup button,
- sent the form
- closed window
- click on non-popup
, and it will also put him on target.
so in my snipplet i clear the target in case of data-target = ''
if you want to mark only one element as a popup, you will need to clone your form: http://jsfiddle.net/oceog/gArdk/2/
JS:
$('button.Submit.popup').click( function() { var t=$(this); var form=t.parents('form').clone(true).attr('target','_blank'); form.submit(); return false; });
HTML:
<form id='double' method="GET" action="http://google.com/search"> <input name="q" type="text"> <button class="Submit"> Submmit here</button> <button class="Submit popup"> Open new</button> </form>
source share