Click to See Complete Forum and Search --> : Dynamic url for src= Need help


kmg
02-25-2003, 04:39 AM
Hi all,
I'm having problems generating a url for src="...." in Javascript.
The scenario is, I need to call a page with a variable, parse that
variable to create two variables for a src="...." statement. I cant
get it to work.

I call http://localhost/brochure.htm?P=1234R4567 and brochure.htm
is as below but the call to brochure.cgi does not contain any values.
Agentid and Propref are set correctly but the values do not get passed
to the cgi script.

Any ideas would be gratefully received - I'm at my wits end!

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<head></head>
<body>
<SCRIPT language="javascript"
urlquery=location.href.split("?");
Propref=urlquery[1].split("=");
Agentid=Propref[1].split("R");
Propref=Propref[1];
Agentid=Agentid[0];
src="http://localhost/cgi-bin/r/brochure.cgi?A=" + Agentid + "&P=" + Propref;
>
</script>

<noscript>
You need to enable Javascript to view this page<br>
Click <b>Tools, Internet Options, Security, Custom, Scripting Enable</b>
</noscript>
</body>
</html>

gil davis
02-25-2003, 05:40 AM
There is no ">" at the end of your script tag. It seems that you think the entire script resides within the tag, and that is not correct.

I assume that you want the page to just do a redirect to the cgi. If so, this should do what you want:<SCRIPT language="javascript">
if (location.href.indexOf("?") != -1)
{urlquery = location.href.split("?");
Propref = urlquery[1].split("=");
Agentid = Propref[1].split("R");
Propref = Propref[1];
Agentid = Agentid[0];
location.href = "http://localhost/cgi-bin/r/brochure.cgi?A=" + Agentid + "&P=" + Propref;}
</script>

kmg
02-25-2003, 05:51 AM
Hi Gill
No, brochure.htm is essentially a template which is called with a parameter.

The javascript is to construct a call to brochure.cgi.

The brochure.cgi call will return results based on that parameter and incorporate that output in brochure.htm.

gil davis
02-25-2003, 06:14 AM
Originally posted by kmg
The javascript is to construct a call to brochure.cgi ... The brochure.cgi call will return results based on that parameter and incorporate that output in brochure.htm.How do you define "call"? Client-side javascript cannot "call" something from the server.

kmg
02-25-2003, 08:18 AM
OK, wrong terminology I suppose.

It's like an include.
This works OK and shows the output of brochure.cgi where the javascript is inserted.
<SCRIPT language="javascript"
var urlquery=location.href.split("?");
var $Propref=urlquery[1].split("=");
var $Agentid=$Propref[1].split("R");
$Propref=$Propref[1];
$Agentid=$Agentid[0];
src="http://127.0.0.1/cgi-bin/r/brochure.cgi?A=999&P=999R1234";
></script>

This doesn't work because nothing after the first '=' gets passed to brochure.cgi

<SCRIPT language="javascript"
var urlquery=location.href.split("?");
var $Propref=urlquery[1].split("=");
var $Agentid=$Propref[1].split("R");
$Propref=$Propref[1];
$Agentid=$Agentid[0];
src="http://127.0.0.1/cgi-bin/r/brochure.cgi?A=" + $Agentid = "&P=" + $Propref + ";";
></script>

gil davis
02-25-2003, 09:13 AM
I have no experience with includes, and (probably due to that) I am still having trouble with your <SCRIPT> tag. It would appear the the SERVER would have to create the strings necessary.

Is the "call" supposed to happen at the SERVER or at the CLIENT?

kmg
02-25-2003, 12:15 PM
Hi Gill
The 'call' is generated by the client and executed by the server.
The output from the server is then displayed, inline, on the client, in the same page as the call is generated.

I'm working on a second-best solution using frames, through I don't like it! It generates three frames, header, results from brochure.cgi and footer.

It works but it's hardly elegant!

Thanks for the help so far, and if you have any inspiration, I'll be deligted.
Regards
KM