SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    Jun 2000
    Posts
    165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How are you today?

    I wonder if you can help me please?

    I'm trying to create a select menu of links to other sites that when clicked on, opens up a new window (i.e. using Javascript) displaying the link selected by the user.

    After clicking a 'go' button, I'd like the form action to call up the script gotolink.php3, but the following line does not give me the value of the variable $chosenlink (i.e. what the user selected).

    <?php
    echo "chosenlink is $chosenlink<br>";
    ?>

    Does somebody know why please?

    I realise that I probably don't need both of these Javascript functions, but for now this is the way things are structured.

    I further realise that I probably don't need to go via the php script (gotolink.php3), but
    this is important to me, because I'd like to apply the same principle to other areas as well.

    I'd prefer not to use a jump menu if poss, but instead a select menu with a 'go' button next to it.

    <head>
    <script language=javascript>

    function helpwindow(popup,Height)
    {
    helpWindow = window.open(popup,"helpWin","toolbar=no,scrollbars=yes,location=no,width=470,height=450");
    }

    function infowindow(info,Height)
    {
    helpWindow = window.open(info,"helpWin","toolbar=no,scrollbars=yes,resize=yes,location=no,width=350,height=50");
    }

    </script>
    </head>

    <form method="post" action="javascript:infowindow('gotolink.php3', 400)">

    <select name="chosenlink">
    <option selected>www.yahoo.com</option>
    <option>www.google.com</option>
    <option>www.altavista.com</option>
    </select>
    <input type = "Submit" name = "go" value = "go">
    </form>

    Thanks very much if you can tell me why this code isn't passing the variable $chosenlink.

    All the best,

    Ben.

  2. #2
    You talkin to me? Anarchos's Avatar
    Join Date
    Oct 2000
    Location
    Austin, TX
    Posts
    1,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It would be a lot simpler to eliminate the PHP redirection script altogether, unless you needed it for some other reason (like tallying the links or something). Here's what I'd do:

    function infowindow(info)
    {
    helpWindow = window.open(info,"helpWin","toolbar=no,scrollbars=yes,resize=yes,location=no,width=350,height=400");
    }

    </script>
    </head>

    <form>
    <select onChange="infoWindow(this.options[this.selectedIndex].value)">
    <option selected value="http://www.yahoo.com">www.yahoo.com</option>
    <option value="http://www.google.com">www.google.com</option>
    <option value="http://www.altavista.com">www.altavista.com</option>
    </select>
    <input type="Submit" name="go" value="go">
    </form>

    The reason gotolink isn't getting the form input is because when you called the javascript to open the window you weren't submitting the form into to the new window, you were just opening the URL of "gotolink.php3". If you still want to use gotolink.php3, I would modify my method to pass the values you want on the URL itself.

  3. #3
    SitePoint Zealot
    Join Date
    Jun 2000
    Posts
    165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank you very much Anarchos!!!

  4. #4
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi backpack,

    I'm not certain what your php statement does. However, if you want to extract the values from the selection list, you can use the opener property. You would have to give the form a name, as in:

    <form name='myLinker' method="post" action="javascript:infowindow('gotolink.php3', 400)">

    and then in the gotolink.php3 page:

    var myLink = opener.document.myLinker.chosenLink.options[opener.document.myLinker.chosenLink.selectedIndex].value


    Vinny


    Where the World Once Stood
    the blades of grass
    cut me still


Bookmarks

Posting Permissions

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