I need to make a button’s target different from the main submit value. I am using jquery with code below:
HTML:
<form action="somepage" id="cartform" target="_parent" method="post">
(So default action is parent)
JQUERY:
$("#refresh").click(function(){
$("#cartform").attr('target', '_self');
});
(“Refresh” is the form’s extra button to keep the form in a popup box)
Try to add a listener on submit instead of click:
Obv it’s the case only if you always want the target to change as the form is submitted. Otherwise, try with your code and
preventDefault.I think the form is being submitted before the
targetchange applies.Edit
Actually, OP is trying to submit a form inside an iframe. This should work:
Will submit to: