How to Make a form not open a new window when it submits a url action?
I have a form that submits a url action. However I don't want it to open up a new window with the url when it is submitted. How should I avoid this?
<form name="leds" id="ledSend" method="get" target="_blank" action="https://agent.electricimp.com/Fk43xPMkSrWF">
Lamp Control: <input type="radio" name="led" value="0" checked>Off
<input type="radio" name="led" value="1">On<br>
How long should the Lights stay on? <input type="text" name="timer" value="10">seconds<br>
Your name? For Our Records <input id="name" type="text" name="user" placeholder="Your name here"> <br>
<input type="submit" value="Update!" onclick="alert(theInput.value)"/>
<script>
var theInput = document.getElementById("name");
I don't want this form to change windows to
https://agent.electricinp.com
When it is submitted. How would I avoid this so that the user stays on the original page where they submit the form form.
javascript php html forms
add a comment |
I have a form that submits a url action. However I don't want it to open up a new window with the url when it is submitted. How should I avoid this?
<form name="leds" id="ledSend" method="get" target="_blank" action="https://agent.electricimp.com/Fk43xPMkSrWF">
Lamp Control: <input type="radio" name="led" value="0" checked>Off
<input type="radio" name="led" value="1">On<br>
How long should the Lights stay on? <input type="text" name="timer" value="10">seconds<br>
Your name? For Our Records <input id="name" type="text" name="user" placeholder="Your name here"> <br>
<input type="submit" value="Update!" onclick="alert(theInput.value)"/>
<script>
var theInput = document.getElementById("name");
I don't want this form to change windows to
https://agent.electricinp.com
When it is submitted. How would I avoid this so that the user stays on the original page where they submit the form form.
javascript php html forms
add a comment |
I have a form that submits a url action. However I don't want it to open up a new window with the url when it is submitted. How should I avoid this?
<form name="leds" id="ledSend" method="get" target="_blank" action="https://agent.electricimp.com/Fk43xPMkSrWF">
Lamp Control: <input type="radio" name="led" value="0" checked>Off
<input type="radio" name="led" value="1">On<br>
How long should the Lights stay on? <input type="text" name="timer" value="10">seconds<br>
Your name? For Our Records <input id="name" type="text" name="user" placeholder="Your name here"> <br>
<input type="submit" value="Update!" onclick="alert(theInput.value)"/>
<script>
var theInput = document.getElementById("name");
I don't want this form to change windows to
https://agent.electricinp.com
When it is submitted. How would I avoid this so that the user stays on the original page where they submit the form form.
javascript php html forms
I have a form that submits a url action. However I don't want it to open up a new window with the url when it is submitted. How should I avoid this?
<form name="leds" id="ledSend" method="get" target="_blank" action="https://agent.electricimp.com/Fk43xPMkSrWF">
Lamp Control: <input type="radio" name="led" value="0" checked>Off
<input type="radio" name="led" value="1">On<br>
How long should the Lights stay on? <input type="text" name="timer" value="10">seconds<br>
Your name? For Our Records <input id="name" type="text" name="user" placeholder="Your name here"> <br>
<input type="submit" value="Update!" onclick="alert(theInput.value)"/>
<script>
var theInput = document.getElementById("name");
I don't want this form to change windows to
https://agent.electricinp.com
When it is submitted. How would I avoid this so that the user stays on the original page where they submit the form form.
javascript php html forms
javascript php html forms
asked Nov 25 '14 at 0:27
sTr8_StrugginsTr8_Struggin
376721
376721
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Get rid of target="_blank"
<form name="leds" id="ledSend" method="get" action="">
This still leaves the original page and goes to agent.electricimp.com/Fk43xPMkSrWF
– sTr8_Struggin
Nov 25 '14 at 0:29
That's where you send them. What did you expect to happen?
– John Conde
Nov 25 '14 at 0:29
Is there a way to stay on the original page but still make the http request to the site?
– sTr8_Struggin
Nov 25 '14 at 0:29
3
I think OP is looking for AJAX submit
– Neverever
Nov 25 '14 at 0:30
1
That's waaaayyyyy too broad for this website
– John Conde
Nov 25 '14 at 0:34
|
show 4 more comments
Recently I got this scenario and researched a lot to find the hack/solution.
Solution - If you can put a window names and refer same every time, then browser will make sure to open new tab if not opened already, otherwise it will just refresh the window.
Example snippet: Demo JSfiddle here
<form id="myForm" action="<URL>" method="POST" target="_blank" onsubmit="target_popup(this)">
First name: <input type="text" name="fname"/><br/>
Last name: <input type="text" name="lname"/><br/>
<button type="submit" id="btnTest"> Submit</button>
</form>
<script>
var target_popup = function(form) {
window.open('',//URL should be blank so that it will take form attributes.
'UniqueWindowName', //window name
'width=400,height=400,resizeable,scrollbars');
form.target = 'UniqueWindowName';
}
</script>
Please refer my blog for more details
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f27116748%2fhow-to-make-a-form-not-open-a-new-window-when-it-submits-a-url-action%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Get rid of target="_blank"
<form name="leds" id="ledSend" method="get" action="">
This still leaves the original page and goes to agent.electricimp.com/Fk43xPMkSrWF
– sTr8_Struggin
Nov 25 '14 at 0:29
That's where you send them. What did you expect to happen?
– John Conde
Nov 25 '14 at 0:29
Is there a way to stay on the original page but still make the http request to the site?
– sTr8_Struggin
Nov 25 '14 at 0:29
3
I think OP is looking for AJAX submit
– Neverever
Nov 25 '14 at 0:30
1
That's waaaayyyyy too broad for this website
– John Conde
Nov 25 '14 at 0:34
|
show 4 more comments
Get rid of target="_blank"
<form name="leds" id="ledSend" method="get" action="">
This still leaves the original page and goes to agent.electricimp.com/Fk43xPMkSrWF
– sTr8_Struggin
Nov 25 '14 at 0:29
That's where you send them. What did you expect to happen?
– John Conde
Nov 25 '14 at 0:29
Is there a way to stay on the original page but still make the http request to the site?
– sTr8_Struggin
Nov 25 '14 at 0:29
3
I think OP is looking for AJAX submit
– Neverever
Nov 25 '14 at 0:30
1
That's waaaayyyyy too broad for this website
– John Conde
Nov 25 '14 at 0:34
|
show 4 more comments
Get rid of target="_blank"
<form name="leds" id="ledSend" method="get" action="">
Get rid of target="_blank"
<form name="leds" id="ledSend" method="get" action="">
answered Nov 25 '14 at 0:28
John CondeJohn Conde
186k80374428
186k80374428
This still leaves the original page and goes to agent.electricimp.com/Fk43xPMkSrWF
– sTr8_Struggin
Nov 25 '14 at 0:29
That's where you send them. What did you expect to happen?
– John Conde
Nov 25 '14 at 0:29
Is there a way to stay on the original page but still make the http request to the site?
– sTr8_Struggin
Nov 25 '14 at 0:29
3
I think OP is looking for AJAX submit
– Neverever
Nov 25 '14 at 0:30
1
That's waaaayyyyy too broad for this website
– John Conde
Nov 25 '14 at 0:34
|
show 4 more comments
This still leaves the original page and goes to agent.electricimp.com/Fk43xPMkSrWF
– sTr8_Struggin
Nov 25 '14 at 0:29
That's where you send them. What did you expect to happen?
– John Conde
Nov 25 '14 at 0:29
Is there a way to stay on the original page but still make the http request to the site?
– sTr8_Struggin
Nov 25 '14 at 0:29
3
I think OP is looking for AJAX submit
– Neverever
Nov 25 '14 at 0:30
1
That's waaaayyyyy too broad for this website
– John Conde
Nov 25 '14 at 0:34
This still leaves the original page and goes to agent.electricimp.com/Fk43xPMkSrWF
– sTr8_Struggin
Nov 25 '14 at 0:29
This still leaves the original page and goes to agent.electricimp.com/Fk43xPMkSrWF
– sTr8_Struggin
Nov 25 '14 at 0:29
That's where you send them. What did you expect to happen?
– John Conde
Nov 25 '14 at 0:29
That's where you send them. What did you expect to happen?
– John Conde
Nov 25 '14 at 0:29
Is there a way to stay on the original page but still make the http request to the site?
– sTr8_Struggin
Nov 25 '14 at 0:29
Is there a way to stay on the original page but still make the http request to the site?
– sTr8_Struggin
Nov 25 '14 at 0:29
3
3
I think OP is looking for AJAX submit
– Neverever
Nov 25 '14 at 0:30
I think OP is looking for AJAX submit
– Neverever
Nov 25 '14 at 0:30
1
1
That's waaaayyyyy too broad for this website
– John Conde
Nov 25 '14 at 0:34
That's waaaayyyyy too broad for this website
– John Conde
Nov 25 '14 at 0:34
|
show 4 more comments
Recently I got this scenario and researched a lot to find the hack/solution.
Solution - If you can put a window names and refer same every time, then browser will make sure to open new tab if not opened already, otherwise it will just refresh the window.
Example snippet: Demo JSfiddle here
<form id="myForm" action="<URL>" method="POST" target="_blank" onsubmit="target_popup(this)">
First name: <input type="text" name="fname"/><br/>
Last name: <input type="text" name="lname"/><br/>
<button type="submit" id="btnTest"> Submit</button>
</form>
<script>
var target_popup = function(form) {
window.open('',//URL should be blank so that it will take form attributes.
'UniqueWindowName', //window name
'width=400,height=400,resizeable,scrollbars');
form.target = 'UniqueWindowName';
}
</script>
Please refer my blog for more details
add a comment |
Recently I got this scenario and researched a lot to find the hack/solution.
Solution - If you can put a window names and refer same every time, then browser will make sure to open new tab if not opened already, otherwise it will just refresh the window.
Example snippet: Demo JSfiddle here
<form id="myForm" action="<URL>" method="POST" target="_blank" onsubmit="target_popup(this)">
First name: <input type="text" name="fname"/><br/>
Last name: <input type="text" name="lname"/><br/>
<button type="submit" id="btnTest"> Submit</button>
</form>
<script>
var target_popup = function(form) {
window.open('',//URL should be blank so that it will take form attributes.
'UniqueWindowName', //window name
'width=400,height=400,resizeable,scrollbars');
form.target = 'UniqueWindowName';
}
</script>
Please refer my blog for more details
add a comment |
Recently I got this scenario and researched a lot to find the hack/solution.
Solution - If you can put a window names and refer same every time, then browser will make sure to open new tab if not opened already, otherwise it will just refresh the window.
Example snippet: Demo JSfiddle here
<form id="myForm" action="<URL>" method="POST" target="_blank" onsubmit="target_popup(this)">
First name: <input type="text" name="fname"/><br/>
Last name: <input type="text" name="lname"/><br/>
<button type="submit" id="btnTest"> Submit</button>
</form>
<script>
var target_popup = function(form) {
window.open('',//URL should be blank so that it will take form attributes.
'UniqueWindowName', //window name
'width=400,height=400,resizeable,scrollbars');
form.target = 'UniqueWindowName';
}
</script>
Please refer my blog for more details
Recently I got this scenario and researched a lot to find the hack/solution.
Solution - If you can put a window names and refer same every time, then browser will make sure to open new tab if not opened already, otherwise it will just refresh the window.
Example snippet: Demo JSfiddle here
<form id="myForm" action="<URL>" method="POST" target="_blank" onsubmit="target_popup(this)">
First name: <input type="text" name="fname"/><br/>
Last name: <input type="text" name="lname"/><br/>
<button type="submit" id="btnTest"> Submit</button>
</form>
<script>
var target_popup = function(form) {
window.open('',//URL should be blank so that it will take form attributes.
'UniqueWindowName', //window name
'width=400,height=400,resizeable,scrollbars');
form.target = 'UniqueWindowName';
}
</script>
Please refer my blog for more details
edited Nov 16 '18 at 4:59
answered Nov 16 '18 at 4:49
Pradeepkumar'2552866Pradeepkumar'2552866
13
13
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f27116748%2fhow-to-make-a-form-not-open-a-new-window-when-it-submits-a-url-action%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown