Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-25-2009, 05:39 AM   PM User | #1
xenoche
New to the CF scene

 
Join Date: Jul 2009
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
xenoche is an unknown quantity at this point
Using checkboxes to open links in new windows.

Hi all!

Javascript newbie here. I am trying to setup a javascript code that will open links to items that are checked. Is this possible by client side without using CGI?
xenoche is offline   Reply With Quote
Old 07-25-2009, 07:41 AM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,103
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Checkboxes are not very suitable for this as the user can select multiple boxes. Prefer to use radio buttons:-


Code:
<form name= "myform">

Google <input type = "radio" name = "rad1" onclick = "go()">
Coding Forums <input type = "radio" name = "rad1" onclick = "go()">
JavaScriptKit <input type = "radio" name = "rad1" onclick = "go()">

</form>

<script type = "text/javascript">

function go() {
var sel;
for (var i =0; i<document.myform.rad1.length; i++) {
if (document.myform.rad1[i].checked) {
sel = i;
}
}
if (sel == 0) {window.location = "http://www.google.com"}
if (sel == 1) {window.location = "http://www.codingforums.com"}
if (sel == 2) {window.location = "http://www.javascriptkit.com"}
}
</script>

Quizmaster: What is a 12-sided solid figure called?
Contestant: Well, I know that ten sides is a hexagon. So I'll say an octogon.
Philip M is offline   Reply With Quote
Old 07-26-2009, 06:31 PM   PM User | #3
xenoche
New to the CF scene

 
Join Date: Jul 2009
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
xenoche is an unknown quantity at this point
Quote:
Originally Posted by Philip M View Post
Checkboxes are not very suitable for this as the user can select multiple boxes. Prefer to use radio buttons:-
Thanks for responding. But the whole point is for the user to HAVE the option to select multiple links, I need it to launch all the links selected by the user.
xenoche is offline   Reply With Quote
Old 07-26-2009, 07:18 PM   PM User | #4
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,103
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Quote:
Originally Posted by xenoche View Post
Thanks for responding. But the whole point is for the user to HAVE the option to select multiple links, I need it to launch all the links selected by the user.
What, all at once?

Code:
<form name= "myform">
Google <input type = "checkbox" name = "chk1">
Coding Forums <input type = "checkbox" name = "chk2">
JavaScriptKit <input type = "checkbox" name = "chk3">
<br><br>
<input type = "button" name = "but1" value = "Launch selected URLs" onclick = "go()">
</form>

<script type = "text/javascript">

function go() {
if (document.myform.chk1.checked == true) {window.open("http://www.google.com","window1")}
if (document.myform.chk2.checked == true) {window.open("http://www.codingforums.com","window2")}
if (document.myform.chk3.checked == true) {window.open ("http://www.javascriptkit.com","window3")}
} 

</script>
You can add attributes to each window, such as width, height, resizable, scrollbars, toolbar etc.

Example:-

if (document.myform.chk1.checked == true) {window.open("http://www.google.com","window1",'width=800,height=600,scrollbars=yes,resizable=no,toolbar=yes')}
Philip M is offline   Reply With Quote
Users who have thanked Philip M for this post:
xenoche (07-27-2009)
Old 07-26-2009, 10:06 PM   PM User | #5
xenoche
New to the CF scene

 
Join Date: Jul 2009
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
xenoche is an unknown quantity at this point
Thank you very much for your help, Phil. Much appreciated. Let me try this code out when I get home from work.

Thanks again!
xenoche is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:22 AM.


Advertisement
Log in to turn off these ads.