I'm not sure if it's possible to open multiple tabs/windows within one method, as window.open will stop the current JavaScript-method running. It IS possible to open multiple windows, but there is a catch to it. You must enable pop-ups, which most people have disabled by default. Then there is the browser-issue: as a developer, you can't decide whether the browser opens up a new tab, or a new window. What you can do to show multiple tabs/windows, is use the piece of JavaScript I copied at the bottom of my answer. Note though, that while it works, it opens up only ONE tab, the rest are new 'pop-up'-windows (atleast in Chrome).
This code does work if you need to open one page, and one page only though.
Using jQuery might make your life a lot easier:
HTML
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"> </script>
<script type="text/javascript" src="boxes.js"></script>
</head>
<body>
<input type="checkbox" name="box1" value="box1" id="box1"><label>box1</label><br/>
<input type="checkbox" name="box2" value="box2" id="box2"><label>box2</label><br/>
<input type="checkbox" name="box3" value="box3" id="box3"><label>box3</label><br/>
<input type="checkbox" name="box4" value="box4" id="box4"><label>box4</label><br/>
<input type="button" value="Submit" name="submitButton" onclick="submit()">
</body>
</html>
JavaScript (jQuery)
function submit() {
var box1 = $('#box1');
var box2 = $('#box2');
var box3 = $('#box3');
var box4 = $('#box4');
if (box1.prop('checked')) {
goToUrl('http://box1url.com');
//Redirect by box1
}
if (box2.prop('checked')) {
goToUrl('http://box2url.com');
//Redirect by box2
}
if (box3.prop('checked')) {
goToUrl('http://box3url.com');
//Redirect by box3
}
if (box4.prop('checked')) {
goToUrl('http://box4url.com');
//Redirect by box4
}
}
function goToUrl(url) {
var win = window.open(url, '_blank');
win.focus();
}
EDIT: WITHOUT JQUERY
Might you decide not to use jQuery, you could use this for JavaScript:
function submit() {
var box1 = document.getElementById('box1');
var box2 = document.getElementById('box2');
var box3 = document.getElementById('box3');
var box4 = document.getElementById('box4');
if (box1.checked) {
goToUrl('http://box1url.com');
//Redirect by box1
}
if (box2.checked) {
goToUrl('http://box2url.com');
//Redirect by box2
}
if (box3.checked) {
goToUrl('http://box3url.com');
//Redirect by box3
}
if (box4.checked) {
goToUrl('http://box4url.com');
//Redirect by box4
}
}
function goToUrl(url) {
var win = window.open(url, '_blank');
win.focus();
}
EDIT2: Added 'multi-url'
var urls = []; //Initialize empty array
if (box1.checked) {
urls.push('http://box1url.com'); // If box is checked, push the url
}
urls.forEach(function(url) {
goToUrl(url); //Go to all URLs in a for-each loop
});
EDIT3: Added more 'dynamic' URLs by values
If setting the URL as a value for the checkbox, you can retrieve it in the JavaScript afterwards:
HTML:
<input type="checkbox" name="box1" value="http://box1url.com" id="box1"><label>box1</label><br/>
JavaScript (no jQuery):
if (box1.checked) {
urls.push(box1.value);
//Redirect by box1
}
JavaScript (jQuery):
if (box1.prop('checked')) {
urls.push(box1.value);
//Redirect by box1
}
EDIT4: Full code
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript" src="no-j-boxes.js"></script>
</head>
<body>
<input type="checkbox" name="box1" value="http://box1url.com" id="box1"><label>box1</label><br/>
<input type="checkbox" name="box2" value="http://box2url.com" id="box2"><label>box2</label><br/>
<input type="checkbox" name="box3" value="http://box3url.com" id="box3"><label>box3</label><br/>
<input type="checkbox" name="box4" value="http://box4url.com" id="box4"><label>box4</label><br/>
<input type="button" value="Submit" name="submitButton" onclick="submit()">
</body>
</html>
JavaScript:
function submit() {
var box1 = document.getElementById('box1');
var box2 = document.getElementById('box2');
var box3 = document.getElementById('box3');
var box4 = document.getElementById('box4');
var urls = [];
if (box1.checked) {
urls.push(box1.value);
}
if (box2.checked) {
urls.push(box2.value);
}
if (box3.checked) {
urls.push(box3.value);
}
if (box4.checked) {
urls.push(box4.value);
}
urls.forEach(function(url) {
goToUrl(url);
});
}
function goToUrl(url) {
var win = window.open(url, '_blank');
}