ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: Windows XP. I gave up with Linux & I left LQ.
Posts: 502
Rep:
Javascript Menu help
I am trying to add this menu to my website. It will Have links across the top and when you click on each link it shows a list in the drop down box below for that link.
It works fine. But what I want to do is have each link that is clicked on in the drop down menu to open in a seperate window. I tried the classic target="_blank" but that didn't work, surprise lol. Just by looking at this can anyone give me any ideas? I know this may be a bit vague but I really don't know about programming in javascript. I am slowly teaching myself c++ and I don't want to get to involved with similiar things yet but I know how I want my website and I want these links to open in a seperate window, lol.
Here is the code in two parts. Head and body. Thanks.
menu[0][0]=new Option("Yahoo","http://www.yahoo.com" )
menu[0][1]=new Option("","")
menu[0][2]=new Option("","")
function fillList(z){
for (a=document.f.s.options.length-1;a>0;a--){document.f.s.options[a]=null}
for (a=0;a<menu[z].length;a++){document.f.s.options[a]=new
Option(menu[z][a].text,menu[z][a].value)
}
document.f.s.selectedIndex=0
}
//-->
</SCRIPT>
</head>
<body>
<FORM NAME=f>
<A HREF=Javascript:fillList(0)>One</A>
<A HREF=Javascript:fillList(1)>Two</A>
<A HREF=Javascript:fillList(2)>Three</A>
<BR>
<SELECT NAME=s style="width:225">
<OPTION VALUE="#">Where do you want to go?
</SELECT>
<!--// Clicking this button will take you to the url that corresponds to the choice you made from the drop down //-->
<INPUT TYPE=button onclick="location=document.f.s.options[document.f.s.selectedIndex].value" VALUE=">>">
</FORM></center>
Distribution: Windows XP. I gave up with Linux & I left LQ.
Posts: 502
Original Poster
Rep:
Quote:
Originally posted by mirradric You are asking a question about javascript, not java. They are different. I've not done javascript for about 5 years so I can't help you.
Lol, oops. I thought I wrote Javascript, not java. I have been playing around with different menu's all day. Things are blurring together
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789
Rep:
There's no 'target="_blank"' in your script, so no surprise it doesn't open a new window.
What you need to do is to open a new window in your onclick handler by calling a custom function.
Another problem, but it's not your fault, LQ Forums split "javascript" in "java script" in the A tag HREF, so a cut/paste breaks the code, even using the code tag doesn't help, but you should do it anyway as it improves code readability.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.