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. <head> <SCRIPT LANGUAGE=JavaScript> <!--// menu=new Array() menu[0]=new Array() menu[1]=new Array() menu[2]=new Array() 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> </body> Webwolf |
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.
|
Quote:
Lol, oops. I thought I wrote Javascript, not java. I have been playing around with different menu's all day. Things are blurring together :( Webwolf |
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. |
i havent used javascript in a while, but try for each link's onClick() method new window("URL","width, height");
ex. <a href=javascript:onClick()=new window("URL","width, height");></a> i dont remember if some of that needs quotes around it |
damn it, LQ put that smiley in after "javascript", its supposed to be a colon (:) followed by onClick
|
All times are GMT -5. The time now is 11:48 AM. |