/    Sign up×
Community /Pin to ProfileBookmark

Submitting a form to a new window

I have a form with two submit buttons, button A and button B.

I want button A to submit the form to a new window, but I want button B to keep it in the same window.

Here is the code I’ve got it working so that it will make both buttons submit the form into new windows:

[code=php]<html>

<head>
<title>Untitled</title>
<script>
function doSomething(form) {
var w = window.open(”,’new_window’);
form.target = ‘new_window’;
}
</script>
</head>

<body>

<form action=”index.php” name=”form” onsubmit=”doSomething(this);”>
<p><input type=”submit” name=”button A” /><input type=”submit” name=”button B” /> </p>
</form>
</body>
</html>[/code]

But how do I get Button B to submit the form to index.php in the current window while Button A still submits the form to index.php in a new window?

Any help is much appreciated.

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@drgnjucrFeb 16.2005 — I would do something like this:

[CODE]

<script language="javascript">
function doSomething(button) {
theForm = document.form;
if (button == "cmdA") {
var w = window.open('','new_window');
theForm.target = 'new_window';
theForm.submit();
button = "";
}
else {
theForm.submit();
}
}

</script>

[/CODE]


[CODE]

<form action="index.php" name="form" method="post">
<p><input type="button" value="button A" onClick="doSomething('cmdA')"><input type="button" value="button B" onClick="doSomething('cmdB')"> </p>
</form>

[/CODE]


Hope this helps.
×

Success!

Help @Hell_Toupee spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...