SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Oct 2011
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Javascript redirect problem, please help!

    Hi,

    I am very new to Javascript but have found a great tutorial to create a dynamic dropdown menu. I got it to work, but have problems redirecting it to the correct page after the necessary page refresh to load the items in the 2nd dropdown menu.

    The Javascript in the header is the following:

    Code:
    <SCRIPT language=JavaScript> 
    function reload(form){
    var val=form.cat.options[form.cat.options.selectedIndex].value; 
    self.location='index.php?cat=' + val ;}
    </script>
    My PHP controller (index.php) code to load the correct frames is as follows:

    Code:
    <ul id="navbar">
    <li><a href="index.php?id=home">Home</a></li>
    <li><a href="index.php?id=overview">Overview</a></li>
    <li><a href="index.php?id=add">Add new product</a></li>
    </ul>
    Code:
    if(isset($_GET['cat'])){
    include ('add.html.php');}
    else {
    
    	switch($_GET['id'])
    	{
    	default: include('home.html.php');
    	break; case "home": include('home.html.php');
    	break; case "overview": include('add.html.php');
    	break; case "add": include('add.html.php');
    	}
    }
    So I have made a workaround to load the "add.html.php" frame with the if(isset)$_GET['cat']. But what I really would like to do is to change the Javascript self.location to

    Code:
    self.location='index.php?id=toevoegen?cat=' + val ;}
    so that the PHP index script loads the add.html.php automatically. However, when changing the self.location as described above the page is redirected to home.html.php.

    It is really frustrating me, I have googled for a full day but aren't even close to a solution. Therefore I turned to this thread. Can someone please tell me how I can easily load the correct frame by using Javascript?

    Thanks!

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,085
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    You can't use ? twice in the URL. If you want to pass multiple variables you need to use ampersands, like so

    Code:
    ?variable1=value1&variable2=value2&variable3=value3...
    so in your case that would be

    Code:
    self.location='index.php?id=toevoegen&cat=' + val;
    Also note that that link contains "id=toevoegen" as opposed to "id=add" which it looks like you were going for

    if any non-dutch people are reading in here, "toevoegen" in Dutch means "add" (loosely translated).
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  3. #3
    SitePoint Member
    Join Date
    Oct 2011
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi ScallioXTX,

    I see you are also dutch I changed all the names to English for this thread but forgot to translate "toevoegen".

    Anyway, I tried your advice and it's working exactly as I wanted to. In the end it is such a simple solution, but if you don't know you can keep looking in the wrong direction. Thanks a lot for your help!!!!

    Rene

  4. #4
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,085
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Good to hear! And if you ever need more help, we'll be here
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy


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
  •