javascript - Opening multiple pages at once with one script -
i have code below, want open pages user checks, 1 opens right now.
<form> <input type="checkbox" id="site1" name="site1" value="site1">site1<br> <input type="checkbox" id="site2" name="site2" value="site2">site2 <input name="submit" value="check" type="submit" onclick="validate()"> </form>
and script:
function validate() { if (document.getelementbyid('site1').checked) { window.open('http://www.site1.com'); } else { } }
i have in separate scripts maybe there way?
function validate() { if (document.getelementbyid('site2').checked) { window.open('http://www.site2.com'); } else { } }
your answer appreciated!
loop on selected checkboxes , call window.open
.
function validate() { $(":checkbox:checked").each(function() { var sitename = $(this).val(); window.open('http://www.' + sitename + '.com'); }); return false; // prevent form submission }
Comments
Post a Comment