Input text in form-field, generate multiple URLs on submit and open the links in new tabs
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
add a comment |
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
add a comment |
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
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
javascript forms url
edited Jan 2 at 15:19


iLuvLogix
1,599726
1,599726
asked Dec 21 '18 at 10:12
ChrisChris
113
113
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
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);
});
}
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
add a comment |
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>
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
add a comment |
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
- http://www.mywebsite.com/print/hello123
- http://www.anywebsite.com/q=hello123&sort
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
|
show 2 more comments
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%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
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);
});
}
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
add a comment |
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);
});
}
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
add a comment |
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);
});
}
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);
});
}
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
add a comment |
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
add a comment |
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>
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
add a comment |
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>
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
add a comment |
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>
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>
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
add a comment |
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
add a comment |
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
- http://www.mywebsite.com/print/hello123
- http://www.anywebsite.com/q=hello123&sort
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
|
show 2 more comments
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
- http://www.mywebsite.com/print/hello123
- http://www.anywebsite.com/q=hello123&sort
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
|
show 2 more comments
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
- http://www.mywebsite.com/print/hello123
- 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()">
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
- http://www.mywebsite.com/print/hello123
- 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()">
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
|
show 2 more comments
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
|
show 2 more comments
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%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
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