Simple Javascript

Sharky Forums


Results 1 to 6 of 6

Thread: Simple Javascript

  1. #1
    Catfish
    Join Date
    Aug 2001
    Location
    UK
    Posts
    191

    Unhappy Simple Javascript

    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!!
    Last edited by Budda; 04-01-2002 at 01:04 PM.
    "Sharing knowledge is a way of achieving immortality"
    "and thanks for all the fish"

  2. #2
    Ursus Arctos Moderatis Grizzly's Avatar
    Join Date
    Sep 2000
    Location
    Providence, RI USA
    Posts
    3,077
    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:

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

  3. #3
    Catfish
    Join Date
    Aug 2001
    Location
    UK
    Posts
    191
    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.
    "Sharing knowledge is a way of achieving immortality"
    "and thanks for all the fish"

  4. #4
    Expensive Sushi
    Join Date
    May 2001
    Location
    Surrey, BC, Canada
    Posts
    35
    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,direc tories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes ,copyhistory=yes,width=400,height=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.

  5. #5
    Mako Shark dighn's Avatar
    Join Date
    Nov 2000
    Location
    Vancouver, BC Canada
    Posts
    3,171
    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.
    .

  6. #6
    Catfish
    Join Date
    Aug 2001
    Location
    UK
    Posts
    191
    Yes. Now it works fine thanks a lot!!!
    "Sharing knowledge is a way of achieving immortality"
    "and thanks for all the fish"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •