Click to See Complete Forum and Search --> : Simple Javascript


Budda
04-01-2002, 11:58 AM
Hi i have just started learning javascript, but this is really urgent and help would be greatly appreciated:
i am using this javascript, creating a simple dropdown link menue. now i want to change it so that the links open in a new window. sounds simple but i just cant do it. heres the script:

<script language="JavaScript" type="text/javascript">
<!--
// original code by Bill Trefzger 12/12/96
function go1(){
if (document.selecter1.select1.options[document.selecter1.select1.selectedIndex].value != "none") {
location = document.selecter1.select1.options[document.selecter1.select1.selectedIndex].value
}
}
//-->
</script>
<script language="JavaScript" type="text/javascript">
<!--
document.write('<form name="selecter1"><select name="select1" size=1>');
document.write('<option value=none>Searchmachines');
document.write('<option value=none>--------------------');
document.write('<option value="http://www.yahoo.com">Yahoo');
document.write('<option value="http://www.google.com">Google');
document.write('<option value="http://www.metager.de/">Metager');
document.write('<option value="http://uk.yahoo.com">Yahoo UK');
document.write('<option value="http://www.scoot.co.uk">Scoot');
document.write('</select>');
document.write('<input type="button" value="Go" onclick="go1()">');
document.write('</form>');
// end hiding contents -->
</script>

What do i have to change?
Thanks in advance!!

Grizzly
04-01-2002, 01:34 PM
I'm not sure why you're using JavaScript to write out the form like that, but hey, to each his own :) If you wanted the links to open in a new window, try replacing your go1() functon with this:


function go1(){
href=document.selecter1.select1.options[document.selecter1.select1.selectedIndex].value;
if(href != 'none') window.open(href,'gowindow','toolbar=yes');
}

Budda
04-01-2002, 01:45 PM
No, that way I get a "syntax error" message. Thanks for your help anyway!
Is there a better way to create a link list which first opens a user specified message and then opens a new window? If yes I would REALLY like to know.

Triple__J
04-01-2002, 03:35 PM
why don't you try something like this
<html>
<head>

<script type="text/javascript">
function openwindow()
{
window.open("http://www.msn.com","my_new_window","toolbar=yes,location=yes,directories=no,status=no,menubar=ye s,scrollbars=yes,resizable=yes,copyhistory=yes,width=400,hei ght=400")
}
</script>

</head>
<body>

<form>
<input type="button"
value="Open Window"
onclick="openwindow()">
</form>

</body>
</html>


<html>
<head>

<script language="JavaScript">
function source()
{
location="view-source:" + window.location.href
}
</script>

</head>
<body>

<form>
<input type="button" value="View source" onclick="source()">
</form>

</body>
</html>

then you can set the link to what ever you need it to be.

dighn
04-01-2002, 03:56 PM
Originally posted by Budda
No, that way I get a "syntax error" message. Thanks for your help anyway!
Is there a better way to create a link list which first opens a user specified message and then opens a new window? If yes I would REALLY like to know.

what Grizzly said works for me are u sure you did it correctly?

btw you might wnt to remove the extra parameters in window.open() so the new window looks exactly like a normal one.

Budda
04-01-2002, 06:46 PM
Yes. Now it works fine thanks a lot!!!