/    Sign up×
Community /Pin to ProfileBookmark

help with drop down link box

hello i’m new to javascript and i was wondering if there was some way to alter this code that i got off [url]www.htmlgoodies.com[/url] that is for the dropdown link box

i’m sure you all have seen it but here is the code for it:

<SCRIPT LANGUAGE=”javascript”>

function LinkUp()
{
var number = document.DropDown.DDlinks.selectedIndex;
location.href = document.DropDown.DDlinks.options[number].value;
}
</SCRIPT>

<FORM NAME=”DropDown”>
<SELECT NAME=”DDlinks”>
<OPTION SELECTED>–> Choose a Link <–
<OPTION VALUE=”scripttip1.html”> Page One
<OPTION VALUE=”scripttip2.html”> Page Two
<OPTION VALUE=”scripttip3.html”> Page Three
</SELECT>

<INPUT TYPE=”BUTTON” VALUE=”Click to Go!” onClick=”LinkUp()”>
</FORM>

it works great but there is one problem, i’m using frames, the box is on the main frame and it loads to the main frame, i want it to either load up in a blank window or parent window.

if anybody can help me modify this code it would be greatly appriciated, thank you in advance.

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@vwphillipsFeb 24.2005 — I havent tried this in a frameset but should work If not let me know

[code=php]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

<html>

<head>
<title></title>
</head>

<body>
<SCRIPT LANGUAGE="javascript">
// example
// VALUE="SecondFame?http://www.vicsjavascripts.org.uk">
// where
// SecondFrame = your frame name
// http://www.vicsjavascripts.org.uk = the url

number=0

function LinkUp(){
if (number==0){ return; }
Link = document.DropDown.DDlinks.options[number].value.split('?');
if (Link.length==1){
window.top.location=Link;
}
if (Link.length==2){
top.Link[0].location=Link[1];
}
}
</SCRIPT>

<FORM NAME="DropDown">
<SELECT NAME="DDlinks" onchange="javascript:number=this.selectedIndex;" >
<OPTION SELECTED>--> Choose a Link <--
<OPTION VALUE="MainFrame?http://www.vicsjavascripts.org.uk"> Page One
<OPTION VALUE="http://www.vicsjavascripts.org.uk"> Page Two
<OPTION VALUE="SecondFame?http://www.vicsjavascripts.org.uk"> Page Three
</SELECT>

<INPUT TYPE="BUTTON" VALUE="Click to Go!" onClick="LinkUp()">
</FORM>
</body>

</html>
[/code]
Copy linkTweet thisAlerts:
@MoneyMike420authorFeb 25.2005 — I'm sorry but this doesn't seem to be working for me
Copy linkTweet thisAlerts:
@ariadaFeb 25.2005 — Surely you could just alter the linkUp() function:

function LinkUp()

{

var number = document.DropDown.DDlinks.selectedIndex;

top.location.href = document.DropDown.DDlinks.options[number].value;

}
Copy linkTweet thisAlerts:
@vwphillipsFeb 25.2005 — sorry about that

I have tested this

frameset
[code=php]
<html>
<head>
<title>No title</title>
<meta name="description" content="Makes a menu frame in the left. Hyperlinks in the menu frame are targeted to the main frame.">
</head>
<frameset rows="1*" cols="30%, *">
<frame name="contents" src="LF.htm" scrolling="auto" marginwidth="10" marginheight="14" namo_target_frame="detail">
<frame name="detail" id="detail" src="RF.htm" scrolling="no" marginwidth="10" marginheight="14">
<noframes>
<body bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">

<p>You need a browser that supports frame to veiw this page.</p>
</body>
</noframes>
</frameset>
</html>

[/code]


LH.htm
[code=php]

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

<html>

<head>
<title></title>
<SCRIPT LANGUAGE="javascript">

function LinkUp(){
if (document.getElementById('DDlinks').selectedIndex<1){ return; }
Link=document.getElementById('DDlinks').options[document.getElementById('DDlinks').selectedIndex].value.split('?');
if (Link.length==1){
window.top.location=Link[0];
}
if (Link.length==2){
eval('top.'+Link[0]+'.location=Link[1];');
}
}
</SCRIPT>
</head>

<body>
Detail
<FORM NAME="DropDown">
<SELECT NAME="DDlinks" id="DDlinks" onchange="javascript:number=this.selectedIndex;" >
<OPTION SELECTED>--> Choose a Link <--
<OPTION VALUE="detail?http://www.js-examples.com">Page One
<OPTION VALUE="http://www.vicsjavascripts.org.uk">Page Two
<OPTION VALUE="contents?http://www.sitepoint.com">Page Three
</SELECT>

<INPUT TYPE="BUTTON" VALUE="Click to Go!" onClick="LinkUp()">
</FORM>
<br>
</body>

</html>

[/code]
Copy linkTweet thisAlerts:
@MoneyMike420authorFeb 28.2005 — Thank you so much, you are the man
×

Success!

Help @MoneyMike420 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 7.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ,
analytics: Fullres
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: Anonymous,
tipped: article
amount: 1000 SATS,

tipper: Anonymous,
tipped: article
amount: 1000 SATS,

tipper: @Nanditha,
tipped: article
amount: 1000 SATS,
)...