Javascript redirect problem, please help!


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:

<SCRIPT language=JavaScript> 
function reload(form){
self.location='index.php?cat=' + val ;}

My PHP controller (index.php) code to load the correct frames is as follows:

<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>
include ('add.html.php');}
else {

	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

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?


You can’t use ? twice in the URL. If you want to pass multiple variables you need to use ampersands, like so


so in your case that would be

self.location='index.php[COLOR="#0000FF"][B]?[/B][/COLOR]id=toevoegen[B][COLOR="#0000FF"]&[/COLOR][/B]cat=' + val;

Also note that that link contains “id=toevoegen” as opposed to “id=add” which it looks like you were going for :slight_smile:

if any non-dutch people are reading in here, “toevoegen” in Dutch means “add” (loosely translated).

Hi ScallioXTX,

I see you are also dutch :wink: 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!!!


Good to hear! And if you ever need more help, we’ll be here :slight_smile: