PDA

View Full Version : Need to populate a form hidden field with the URL of the referring page



BeemerMonkey
03-14-2008, 04:56 PM
(I'm not a real programmer, I don't even play one on TV).

Here's the set-up:

I have a link (Review This Product) on a page that is going to launch a daughter window (via thickbox if that matters) that contains the review form.

On this product review form there will of course be a bunch of review parameters, but one thing I need to pass is the URL (actually the tail end of the URL that contains the product's ID (i.e. &id=FOO I parse out the part after the =)) in a hidden field.

How could/should this be done?

Should I use javascript to append the parent page's URL to the link that launches the daughter window, or should I use some kind of javascript call that can bring up the referring link's page? (and what would that be or look like)

Any help would be greatly appreciated.

boogyman
03-14-2008, 07:06 PM
I don't believe that Javascript has access to that information

Bob90
03-15-2008, 01:09 PM
If the URL is seen in the address bar then yes yo can do it.



<HTML>
<HEAD>
<SCRIPT type="text/javascript">
function getQuerystrings(inputId) {

var urlString = parent.document.URL;
var queryString = urlString.substring(urlString.indexOf('?'),urlString.length);

//test
alert(urlString+"\n"+queryString);

inputObj = document.getElementById(inputId);
inputObj.value = queryString;

//test
alert(document.getElementById(inputId).value);


}
</SCRIPT>
</HEAD>
<BODY>
<form id="form1">
<input id="urlQuery" type="hidden" value="">
<input type="button" value="Check" onclick="getQuerystrings('urlQuery')">
</form>
</BODY>
</HTML>



See to get it working http://www.webmasterworld.com/forum91/216.htm