[SOLVED] open in new window?

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
mikegotnaild
Forum Contributor
Posts: 173
Joined: Sat Feb 14, 2004 5:59 pm

[SOLVED] open in new window?

Post by mikegotnaild »

I have no knowledge of javascript and i got this script from somewhere but i want these links in the drop down box to go to a separate window when "GO" is clicked. Thanks in advance.

Code: Select all

<?
if (eregi("block-CDC_radio.php",$PHP_SELF)) { Header("Location: index.php"); die(); } 

$content = "<left><form name="radio" >\n";
$content .= "<select name="music" size="1" onChange="displaydesc(document.radio.music.selectedIndex)">\n"; 
$content .= "<option selected>Choose station</option>\n";

// under option value place the specific link to the radio station pls file. simply add another line for each additional station you'd like

$content .= "<option value="http://www.live365.com/stations/jtava?play" target="_blank">Alternative Nation</option>\n";
$content .= "<option value="http://www.live365.com/stations/masmith?play" target="_blank">Rusty Metal Radio</option>\n";
$content .= "<option value="http://www.live365.com/stations/rock7037?play" target="_blank">X FM</option>\n";
$content .= "</select><input type="button" value="Go" onClick="location=document.radio.music.options[document.radio.music.selectedIndex].value"><br>\n";
$content .= "<span id="descriptions" align="left" style="font:italic 13px Arial">\n";
$content .= "</span> </form><script>\n";
$content .= "var textdisplay=new Array()\n";

// add the text you'd like the station to have below. for each additional station add $content .= "textdisplay[[Next Number]]="[Name of Station here]"\n";

$content .= "textdisplay[0]=""\n";
$content .= "textdisplay[1]="Alternative Nation"\n";
$content .= "textdisplay[2]="Rusty Metal Radio"\n";
$content .= "textdisplay[3]="X FM"\n";
$content .= "function displaydesc(which){\n";
$content .= "if (document.all)\n";
$content .= "descriptions.innerHTML=textdisplay[which]\n";
$content .= "else if (document.getElementById)\n";
$content .= "document.getElementById("descriptions").innerHTML=textdisplay[which]\n";
$content .= "}\n";
$content .= "displaydesc(document.radio.music.selectedIndex)\n";
$content .= "document.radio.music.options[0].selected=true\n";
$content .= "</script></p></left>"; 
?>
TheBentinel.com
Forum Contributor
Posts: 282
Joined: Wed Mar 10, 2004 1:52 pm
Location: Columbus, Ohio

Re: open in new window?

Post by TheBentinel.com »

mikegotnaild wrote: <input type="button" value="Go" onClick="location=document.radio.music.options[document.radio.music.selectedIndex].value">
Change the "location=" to "window.open('http://newurl.com', 'NewWindow')"

The syntax may need a little tweking, but that's the idea.

A good javascript resource is http://developer.irt.org/script/script.htm

Hope it helps!
mikegotnaild
Forum Contributor
Posts: 173
Joined: Sat Feb 14, 2004 5:59 pm

Post by mikegotnaild »

THANK YOU! Its always nice when someone anwsers to a newbie question.

Newurl.com should be? theres more than one url..
TheBentinel.com
Forum Contributor
Posts: 282
Joined: Wed Mar 10, 2004 1:52 pm
Location: Columbus, Ohio

Post by TheBentinel.com »

mikegotnaild wrote:Newurl.com should be? theres more than one url..
You're welcome!

In your case, newurl.com would be:

document.radio.music.options[document.radio.music.selectedIndex].value

It's whatever URL you want the new window to display.
Post Reply