GiantDuck
GiantDuck

Reputation: 1064

Prevent submitted form from opening in same popup

My code: <form method='post' target='_blank'... I have multiple of these forms on my page with the same action attribute.

Problem: Only one popup ever opens. If a second form is submitted, it replaces the first form's popup.

How do I get a new popup for each form? (Preferably without changing the action attribute.)

EDIT: I tried adding a random number (Math.floor(Math.random()*1000)) as a null parameter in the action url. This still opens in the same popup.

NOTE: There is no JS being used. However, I'd accept a JS answer.

Upvotes: 0

Views: 290

Answers (1)

Samosa
Samosa

Reputation: 845

Complete working code :-

<html>
<head>
<script>

function popup(form) {
    var popup_id = 'popup_'+form.id
    window.open(form.action, popup_id, 'width=400,height=400,resizeable,scrollbars');
    form.target = popup_id;

}
</script>
</head>
<body>
<form id="form1" action="page.php" onsubmit="popup(this); return false;">

<input type="submit" value="save" />
</form>

<form id="form2" action="page.php" onsubmit="popup(this);return false;">

<input type="submit" value="save" />
</form>
</body>
</html>

Upvotes: 1

Related Questions