How to Make a form not open a new window when it submits a url action?












0















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.










share|improve this question



























    0















    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.










    share|improve this question

























      0












      0








      0








      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.










      share|improve this question














      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 25 '14 at 0:27









      sTr8_StrugginsTr8_Struggin

      376721




      376721
























          2 Answers
          2






          active

          oldest

          votes


















          1














          Get rid of target="_blank"



          <form name="leds" id="ledSend" method="get" action="">





          share|improve this answer
























          • 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



















          0














          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






          share|improve this answer

























            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
            });


            }
            });














            draft saved

            draft discarded


















            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









            1














            Get rid of target="_blank"



            <form name="leds" id="ledSend" method="get" action="">





            share|improve this answer
























            • 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
















            1














            Get rid of target="_blank"



            <form name="leds" id="ledSend" method="get" action="">





            share|improve this answer
























            • 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














            1












            1








            1







            Get rid of target="_blank"



            <form name="leds" id="ledSend" method="get" action="">





            share|improve this answer













            Get rid of target="_blank"



            <form name="leds" id="ledSend" method="get" action="">






            share|improve this answer












            share|improve this answer



            share|improve this answer










            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



















            • 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













            0














            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






            share|improve this answer






























              0














              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






              share|improve this answer




























                0












                0








                0







                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






                share|improve this answer















                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







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 16 '18 at 4:59

























                answered Nov 16 '18 at 4:49









                Pradeepkumar'2552866Pradeepkumar'2552866

                13




                13






























                    draft saved

                    draft discarded




















































                    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.




                    draft saved


                    draft discarded














                    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





















































                    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







                    Popular posts from this blog

                    Xamarin.iOS Cant Deploy on Iphone

                    Glorious Revolution

                    Dulmage-Mendelsohn matrix decomposition in Python