Member Avatar

gtr1971

Hello all! I'm a newbie to Javascript and I have what seems to be a simple task that has stumped me.

I have a parent/child scenario where the child is a pop-up "control panel" with hyperlinks that control the parent page. The idea is to click a link and it changes the parent to whatever URL ...BUT... the kicker here is that the parent page is in PHP and is receiving a value from the javascript function.

I have everything working EXCEPT that I can't get the value from the hyperlink that i need to pass to the PHP. Everything I fund about getting values in JS involves a "getElementby ID" type of command, but that isn't going to work here because there are several hyperlinks. I'm also trying to avoid using an array and looping through it.

I know this must be a simple problem for veteran Javascripters!

HTML FROM CHILD (I made the ID and Value both "2" just for testing purposes):

<a href="#" class="leftlinks" onclick="updateParent(control)" id="2" value="2">CLICK HERE</a>

JAVASCRIPT ACCEPTING THE VALUE:

function updateParent(control) {
	var menukey = return control.value;
	window.opener.location.href="index.php?menukey=" + menukey;
}

The problem lies in populating the "menukey" variable from the hyperlink value.

Where am I going wrong??

instead of

<a href="#" class="leftlinks" onclick="updateParent(control)" id="2" value="2">CLICK HERE</a>

the value needs to be in the function on the link, because the function in the script requires a value.

<a href="#" class="leftlinks" onclick="updateParent(2)" id="2" value="2">CLICK HERE</a>

Plus, just try to use

function updateParent(control) {
    window.opener.location.href="index.php?menukey="+control;
}
Member Avatar

gtr1971

That's it! Thanks a million!