Input text in form-field, generate multiple URLs on submit and open the links in new tabs












2















I'm looking to input text that is then used to generate multiple URLs and open each of them in a different tab.



http://jsfiddle.net/Gv5bq/1/



    <input type="text" id="text" />
<input type="button" id="btn" value="Submit" onClick="javascript: window.open('http://www.mywebsite.com/print/' + document.getElementById('text').value);" />
<input type="button" id="btn" value="Submit" onClick="javascript: window.open('http://www.anywebsite.com/print/' + document.getElementById('text').value);" />


basically does what I need but just for one instead of multiple URLs.



For example:
Input: hello123
On submit open a tab for each of the following URLs
For example www.mywebsite.com/print/hello123/ and www.anywebsite.net/q=hello123&sort










share|improve this question





























    2















    I'm looking to input text that is then used to generate multiple URLs and open each of them in a different tab.



    http://jsfiddle.net/Gv5bq/1/



        <input type="text" id="text" />
    <input type="button" id="btn" value="Submit" onClick="javascript: window.open('http://www.mywebsite.com/print/' + document.getElementById('text').value);" />
    <input type="button" id="btn" value="Submit" onClick="javascript: window.open('http://www.anywebsite.com/print/' + document.getElementById('text').value);" />


    basically does what I need but just for one instead of multiple URLs.



    For example:
    Input: hello123
    On submit open a tab for each of the following URLs
    For example www.mywebsite.com/print/hello123/ and www.anywebsite.net/q=hello123&sort










    share|improve this question



























      2












      2








      2








      I'm looking to input text that is then used to generate multiple URLs and open each of them in a different tab.



      http://jsfiddle.net/Gv5bq/1/



          <input type="text" id="text" />
      <input type="button" id="btn" value="Submit" onClick="javascript: window.open('http://www.mywebsite.com/print/' + document.getElementById('text').value);" />
      <input type="button" id="btn" value="Submit" onClick="javascript: window.open('http://www.anywebsite.com/print/' + document.getElementById('text').value);" />


      basically does what I need but just for one instead of multiple URLs.



      For example:
      Input: hello123
      On submit open a tab for each of the following URLs
      For example www.mywebsite.com/print/hello123/ and www.anywebsite.net/q=hello123&sort










      share|improve this question
















      I'm looking to input text that is then used to generate multiple URLs and open each of them in a different tab.



      http://jsfiddle.net/Gv5bq/1/



          <input type="text" id="text" />
      <input type="button" id="btn" value="Submit" onClick="javascript: window.open('http://www.mywebsite.com/print/' + document.getElementById('text').value);" />
      <input type="button" id="btn" value="Submit" onClick="javascript: window.open('http://www.anywebsite.com/print/' + document.getElementById('text').value);" />


      basically does what I need but just for one instead of multiple URLs.



      For example:
      Input: hello123
      On submit open a tab for each of the following URLs
      For example www.mywebsite.com/print/hello123/ and www.anywebsite.net/q=hello123&sort







      javascript forms url






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 2 at 15:19









      iLuvLogix

      1,599726




      1,599726










      asked Dec 21 '18 at 10:12









      ChrisChris

      113




      113
























          3 Answers
          3






          active

          oldest

          votes


















          0














          You find a code example below



          HTML



          <input type="text" id="text" />
          <input type="button" id="btn" value="Submit" onclick="openURLs(document.getElementById('text').value)"/>


          JavaScript



          function openURLs(url){
          var baseURLs = [`www.mywebsite.com/print/${url}/`, `www.anywebsite.net/q=${url}&sort`]

          baseURLs.forEach(function(u) {
          window.open(u);
          });

          }





          share|improve this answer
























          • Thanks for that but it's not working. Nothing happens when I click 'Submit'.

            – Chris
            Jan 2 at 14:29






          • 1





            Hi @Chris ,the script is correct, but the target domains must allow a window of a different domain to open. meta.stackoverflow.com/questions/337916/…

            – Mahmoud
            Jan 2 at 14:59



















          0














          Please check Always Allow Pop-ups then use this code



          <input type="text" id="text" />
          <input type="button" id="btn" value="Submit" onClick="javascriptFun()" />
          <script>
          function javascriptFun(){
          window.open('http://www.mywebsite.com/print/' + document.getElementById('text').value,'_blank');
          window.open('http://www.mywebsite1.com/print/' + document.getElementById('text').value,'_blank');
          window.open('http://www.mywebsite2.com/print/' + document.getElementById('text').value,'_blank');

          }

          </script>


          enter image description here






          share|improve this answer
























          • thanks for that. How would the code look like if there is some more fixed values after the variable text input, see example from my original question: www.anywebsite.net/q=hello123&sort

            – Chris
            Jan 4 at 14:12





















          0

















          function openURL(){
          var txt = document.getElementById('text').value;
          var link1 = 'http://www.mywebsite.com/print/'+ txt;
          var link2 = 'http://www.anywebsite.com/q='+ txt + '&sort';
          var i;
          for(i = 1; i < 3; i++){
          if(i == 1)
          window.open(link1, '_blank');
          else if (i==2)
          window.open(link2, '_blank');
          }


          }

          <input type="text" id="text" />
          <input value="Submit" type="button" onclick="openURL()">





          I updated the fiddle check here. It will give you result as you want. For Eg: If you enter hello123 below respected url's will be open




          1. http://www.mywebsite.com/print/hello123

          2. http://www.anywebsite.com/q=hello123&sort






          share|improve this answer


























          • Thanks for sharing that but when I hit 'Submit' then nothing happens.

            – Chris
            Jan 2 at 14:34











          • @Chris I updated the answer check it now it will works or check this fiddle jsfiddle.net/Udhaytitus/egyqd5cn

            – Udhay Titus
            Jan 3 at 8:55











          • thanks for that. Unfortunately only one of the 1st of the 2 URLs opens.

            – Chris
            Jan 4 at 14:02











          • check the above jsfiddle both url's are working fine, but you should allow popup for the website.

            – Udhay Titus
            Jan 5 at 4:01






          • 1





            Thanks @Udhay Titus That's exactly what I was looking for!

            – Chris
            Jan 8 at 11:33











          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%2f53882848%2finput-text-in-form-field-generate-multiple-urls-on-submit-and-open-the-links-in%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          3 Answers
          3






          active

          oldest

          votes








          3 Answers
          3






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          You find a code example below



          HTML



          <input type="text" id="text" />
          <input type="button" id="btn" value="Submit" onclick="openURLs(document.getElementById('text').value)"/>


          JavaScript



          function openURLs(url){
          var baseURLs = [`www.mywebsite.com/print/${url}/`, `www.anywebsite.net/q=${url}&sort`]

          baseURLs.forEach(function(u) {
          window.open(u);
          });

          }





          share|improve this answer
























          • Thanks for that but it's not working. Nothing happens when I click 'Submit'.

            – Chris
            Jan 2 at 14:29






          • 1





            Hi @Chris ,the script is correct, but the target domains must allow a window of a different domain to open. meta.stackoverflow.com/questions/337916/…

            – Mahmoud
            Jan 2 at 14:59
















          0














          You find a code example below



          HTML



          <input type="text" id="text" />
          <input type="button" id="btn" value="Submit" onclick="openURLs(document.getElementById('text').value)"/>


          JavaScript



          function openURLs(url){
          var baseURLs = [`www.mywebsite.com/print/${url}/`, `www.anywebsite.net/q=${url}&sort`]

          baseURLs.forEach(function(u) {
          window.open(u);
          });

          }





          share|improve this answer
























          • Thanks for that but it's not working. Nothing happens when I click 'Submit'.

            – Chris
            Jan 2 at 14:29






          • 1





            Hi @Chris ,the script is correct, but the target domains must allow a window of a different domain to open. meta.stackoverflow.com/questions/337916/…

            – Mahmoud
            Jan 2 at 14:59














          0












          0








          0







          You find a code example below



          HTML



          <input type="text" id="text" />
          <input type="button" id="btn" value="Submit" onclick="openURLs(document.getElementById('text').value)"/>


          JavaScript



          function openURLs(url){
          var baseURLs = [`www.mywebsite.com/print/${url}/`, `www.anywebsite.net/q=${url}&sort`]

          baseURLs.forEach(function(u) {
          window.open(u);
          });

          }





          share|improve this answer













          You find a code example below



          HTML



          <input type="text" id="text" />
          <input type="button" id="btn" value="Submit" onclick="openURLs(document.getElementById('text').value)"/>


          JavaScript



          function openURLs(url){
          var baseURLs = [`www.mywebsite.com/print/${url}/`, `www.anywebsite.net/q=${url}&sort`]

          baseURLs.forEach(function(u) {
          window.open(u);
          });

          }






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 21 '18 at 10:29









          MahmoudMahmoud

          612920




          612920













          • Thanks for that but it's not working. Nothing happens when I click 'Submit'.

            – Chris
            Jan 2 at 14:29






          • 1





            Hi @Chris ,the script is correct, but the target domains must allow a window of a different domain to open. meta.stackoverflow.com/questions/337916/…

            – Mahmoud
            Jan 2 at 14:59



















          • Thanks for that but it's not working. Nothing happens when I click 'Submit'.

            – Chris
            Jan 2 at 14:29






          • 1





            Hi @Chris ,the script is correct, but the target domains must allow a window of a different domain to open. meta.stackoverflow.com/questions/337916/…

            – Mahmoud
            Jan 2 at 14:59

















          Thanks for that but it's not working. Nothing happens when I click 'Submit'.

          – Chris
          Jan 2 at 14:29





          Thanks for that but it's not working. Nothing happens when I click 'Submit'.

          – Chris
          Jan 2 at 14:29




          1




          1





          Hi @Chris ,the script is correct, but the target domains must allow a window of a different domain to open. meta.stackoverflow.com/questions/337916/…

          – Mahmoud
          Jan 2 at 14:59





          Hi @Chris ,the script is correct, but the target domains must allow a window of a different domain to open. meta.stackoverflow.com/questions/337916/…

          – Mahmoud
          Jan 2 at 14:59













          0














          Please check Always Allow Pop-ups then use this code



          <input type="text" id="text" />
          <input type="button" id="btn" value="Submit" onClick="javascriptFun()" />
          <script>
          function javascriptFun(){
          window.open('http://www.mywebsite.com/print/' + document.getElementById('text').value,'_blank');
          window.open('http://www.mywebsite1.com/print/' + document.getElementById('text').value,'_blank');
          window.open('http://www.mywebsite2.com/print/' + document.getElementById('text').value,'_blank');

          }

          </script>


          enter image description here






          share|improve this answer
























          • thanks for that. How would the code look like if there is some more fixed values after the variable text input, see example from my original question: www.anywebsite.net/q=hello123&sort

            – Chris
            Jan 4 at 14:12


















          0














          Please check Always Allow Pop-ups then use this code



          <input type="text" id="text" />
          <input type="button" id="btn" value="Submit" onClick="javascriptFun()" />
          <script>
          function javascriptFun(){
          window.open('http://www.mywebsite.com/print/' + document.getElementById('text').value,'_blank');
          window.open('http://www.mywebsite1.com/print/' + document.getElementById('text').value,'_blank');
          window.open('http://www.mywebsite2.com/print/' + document.getElementById('text').value,'_blank');

          }

          </script>


          enter image description here






          share|improve this answer
























          • thanks for that. How would the code look like if there is some more fixed values after the variable text input, see example from my original question: www.anywebsite.net/q=hello123&sort

            – Chris
            Jan 4 at 14:12
















          0












          0








          0







          Please check Always Allow Pop-ups then use this code



          <input type="text" id="text" />
          <input type="button" id="btn" value="Submit" onClick="javascriptFun()" />
          <script>
          function javascriptFun(){
          window.open('http://www.mywebsite.com/print/' + document.getElementById('text').value,'_blank');
          window.open('http://www.mywebsite1.com/print/' + document.getElementById('text').value,'_blank');
          window.open('http://www.mywebsite2.com/print/' + document.getElementById('text').value,'_blank');

          }

          </script>


          enter image description here






          share|improve this answer













          Please check Always Allow Pop-ups then use this code



          <input type="text" id="text" />
          <input type="button" id="btn" value="Submit" onClick="javascriptFun()" />
          <script>
          function javascriptFun(){
          window.open('http://www.mywebsite.com/print/' + document.getElementById('text').value,'_blank');
          window.open('http://www.mywebsite1.com/print/' + document.getElementById('text').value,'_blank');
          window.open('http://www.mywebsite2.com/print/' + document.getElementById('text').value,'_blank');

          }

          </script>


          enter image description here







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 2 at 15:00









          Bhale DinoBhale Dino

          14415




          14415













          • thanks for that. How would the code look like if there is some more fixed values after the variable text input, see example from my original question: www.anywebsite.net/q=hello123&sort

            – Chris
            Jan 4 at 14:12





















          • thanks for that. How would the code look like if there is some more fixed values after the variable text input, see example from my original question: www.anywebsite.net/q=hello123&sort

            – Chris
            Jan 4 at 14:12



















          thanks for that. How would the code look like if there is some more fixed values after the variable text input, see example from my original question: www.anywebsite.net/q=hello123&sort

          – Chris
          Jan 4 at 14:12







          thanks for that. How would the code look like if there is some more fixed values after the variable text input, see example from my original question: www.anywebsite.net/q=hello123&sort

          – Chris
          Jan 4 at 14:12













          0

















          function openURL(){
          var txt = document.getElementById('text').value;
          var link1 = 'http://www.mywebsite.com/print/'+ txt;
          var link2 = 'http://www.anywebsite.com/q='+ txt + '&sort';
          var i;
          for(i = 1; i < 3; i++){
          if(i == 1)
          window.open(link1, '_blank');
          else if (i==2)
          window.open(link2, '_blank');
          }


          }

          <input type="text" id="text" />
          <input value="Submit" type="button" onclick="openURL()">





          I updated the fiddle check here. It will give you result as you want. For Eg: If you enter hello123 below respected url's will be open




          1. http://www.mywebsite.com/print/hello123

          2. http://www.anywebsite.com/q=hello123&sort






          share|improve this answer


























          • Thanks for sharing that but when I hit 'Submit' then nothing happens.

            – Chris
            Jan 2 at 14:34











          • @Chris I updated the answer check it now it will works or check this fiddle jsfiddle.net/Udhaytitus/egyqd5cn

            – Udhay Titus
            Jan 3 at 8:55











          • thanks for that. Unfortunately only one of the 1st of the 2 URLs opens.

            – Chris
            Jan 4 at 14:02











          • check the above jsfiddle both url's are working fine, but you should allow popup for the website.

            – Udhay Titus
            Jan 5 at 4:01






          • 1





            Thanks @Udhay Titus That's exactly what I was looking for!

            – Chris
            Jan 8 at 11:33
















          0

















          function openURL(){
          var txt = document.getElementById('text').value;
          var link1 = 'http://www.mywebsite.com/print/'+ txt;
          var link2 = 'http://www.anywebsite.com/q='+ txt + '&sort';
          var i;
          for(i = 1; i < 3; i++){
          if(i == 1)
          window.open(link1, '_blank');
          else if (i==2)
          window.open(link2, '_blank');
          }


          }

          <input type="text" id="text" />
          <input value="Submit" type="button" onclick="openURL()">





          I updated the fiddle check here. It will give you result as you want. For Eg: If you enter hello123 below respected url's will be open




          1. http://www.mywebsite.com/print/hello123

          2. http://www.anywebsite.com/q=hello123&sort






          share|improve this answer


























          • Thanks for sharing that but when I hit 'Submit' then nothing happens.

            – Chris
            Jan 2 at 14:34











          • @Chris I updated the answer check it now it will works or check this fiddle jsfiddle.net/Udhaytitus/egyqd5cn

            – Udhay Titus
            Jan 3 at 8:55











          • thanks for that. Unfortunately only one of the 1st of the 2 URLs opens.

            – Chris
            Jan 4 at 14:02











          • check the above jsfiddle both url's are working fine, but you should allow popup for the website.

            – Udhay Titus
            Jan 5 at 4:01






          • 1





            Thanks @Udhay Titus That's exactly what I was looking for!

            – Chris
            Jan 8 at 11:33














          0












          0








          0










          function openURL(){
          var txt = document.getElementById('text').value;
          var link1 = 'http://www.mywebsite.com/print/'+ txt;
          var link2 = 'http://www.anywebsite.com/q='+ txt + '&sort';
          var i;
          for(i = 1; i < 3; i++){
          if(i == 1)
          window.open(link1, '_blank');
          else if (i==2)
          window.open(link2, '_blank');
          }


          }

          <input type="text" id="text" />
          <input value="Submit" type="button" onclick="openURL()">





          I updated the fiddle check here. It will give you result as you want. For Eg: If you enter hello123 below respected url's will be open




          1. http://www.mywebsite.com/print/hello123

          2. http://www.anywebsite.com/q=hello123&sort






          share|improve this answer


















          function openURL(){
          var txt = document.getElementById('text').value;
          var link1 = 'http://www.mywebsite.com/print/'+ txt;
          var link2 = 'http://www.anywebsite.com/q='+ txt + '&sort';
          var i;
          for(i = 1; i < 3; i++){
          if(i == 1)
          window.open(link1, '_blank');
          else if (i==2)
          window.open(link2, '_blank');
          }


          }

          <input type="text" id="text" />
          <input value="Submit" type="button" onclick="openURL()">





          I updated the fiddle check here. It will give you result as you want. For Eg: If you enter hello123 below respected url's will be open




          1. http://www.mywebsite.com/print/hello123

          2. http://www.anywebsite.com/q=hello123&sort






          function openURL(){
          var txt = document.getElementById('text').value;
          var link1 = 'http://www.mywebsite.com/print/'+ txt;
          var link2 = 'http://www.anywebsite.com/q='+ txt + '&sort';
          var i;
          for(i = 1; i < 3; i++){
          if(i == 1)
          window.open(link1, '_blank');
          else if (i==2)
          window.open(link2, '_blank');
          }


          }

          <input type="text" id="text" />
          <input value="Submit" type="button" onclick="openURL()">





          function openURL(){
          var txt = document.getElementById('text').value;
          var link1 = 'http://www.mywebsite.com/print/'+ txt;
          var link2 = 'http://www.anywebsite.com/q='+ txt + '&sort';
          var i;
          for(i = 1; i < 3; i++){
          if(i == 1)
          window.open(link1, '_blank');
          else if (i==2)
          window.open(link2, '_blank');
          }


          }

          <input type="text" id="text" />
          <input value="Submit" type="button" onclick="openURL()">






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jan 8 at 11:46

























          answered Dec 21 '18 at 10:45









          Udhay TitusUdhay Titus

          2,59121531




          2,59121531













          • Thanks for sharing that but when I hit 'Submit' then nothing happens.

            – Chris
            Jan 2 at 14:34











          • @Chris I updated the answer check it now it will works or check this fiddle jsfiddle.net/Udhaytitus/egyqd5cn

            – Udhay Titus
            Jan 3 at 8:55











          • thanks for that. Unfortunately only one of the 1st of the 2 URLs opens.

            – Chris
            Jan 4 at 14:02











          • check the above jsfiddle both url's are working fine, but you should allow popup for the website.

            – Udhay Titus
            Jan 5 at 4:01






          • 1





            Thanks @Udhay Titus That's exactly what I was looking for!

            – Chris
            Jan 8 at 11:33



















          • Thanks for sharing that but when I hit 'Submit' then nothing happens.

            – Chris
            Jan 2 at 14:34











          • @Chris I updated the answer check it now it will works or check this fiddle jsfiddle.net/Udhaytitus/egyqd5cn

            – Udhay Titus
            Jan 3 at 8:55











          • thanks for that. Unfortunately only one of the 1st of the 2 URLs opens.

            – Chris
            Jan 4 at 14:02











          • check the above jsfiddle both url's are working fine, but you should allow popup for the website.

            – Udhay Titus
            Jan 5 at 4:01






          • 1





            Thanks @Udhay Titus That's exactly what I was looking for!

            – Chris
            Jan 8 at 11:33

















          Thanks for sharing that but when I hit 'Submit' then nothing happens.

          – Chris
          Jan 2 at 14:34





          Thanks for sharing that but when I hit 'Submit' then nothing happens.

          – Chris
          Jan 2 at 14:34













          @Chris I updated the answer check it now it will works or check this fiddle jsfiddle.net/Udhaytitus/egyqd5cn

          – Udhay Titus
          Jan 3 at 8:55





          @Chris I updated the answer check it now it will works or check this fiddle jsfiddle.net/Udhaytitus/egyqd5cn

          – Udhay Titus
          Jan 3 at 8:55













          thanks for that. Unfortunately only one of the 1st of the 2 URLs opens.

          – Chris
          Jan 4 at 14:02





          thanks for that. Unfortunately only one of the 1st of the 2 URLs opens.

          – Chris
          Jan 4 at 14:02













          check the above jsfiddle both url's are working fine, but you should allow popup for the website.

          – Udhay Titus
          Jan 5 at 4:01





          check the above jsfiddle both url's are working fine, but you should allow popup for the website.

          – Udhay Titus
          Jan 5 at 4:01




          1




          1





          Thanks @Udhay Titus That's exactly what I was looking for!

          – Chris
          Jan 8 at 11:33





          Thanks @Udhay Titus That's exactly what I was looking for!

          – Chris
          Jan 8 at 11:33


















          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%2f53882848%2finput-text-in-form-field-generate-multiple-urls-on-submit-and-open-the-links-in%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

          MongoDB - Not Authorized To Execute Command

          How to fix TextFormField cause rebuild widget in Flutter

          in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith