Home
TeamSite
get javascript variable to perl issue
System
I have some JS in my CGI script. I want to get the JS variable's value into a perl variable. Is this possible? Thanks in advance!
Find more posts tagged with
Comments
JonathonG
Javascript executes on the client machine after the page is rendered. Perl executes on the server machine when the page is requested. So, in a single pass, the answer to your question is "No", i.e. you can't get a javascript variable to a Perl variable. One solution to this would be to have your Javascript page re-post to the CGI, using the value in the javascript variable as one of the post values.
Might I ask what exactly you are trying to accomplish?
Jonathon
Independent Interwoven Contractor
Migrateduser
Hi Jonathon,thank you for your help!
Yes,you are right! I know the runnin mechanism of client-side js and server-side perl too.
I just want to get the template item value to the callout perl variable which is passed to the query statement in the same callout perl code as the parameter,then pass the query result back to the template item value.
How to do it?Can the method post be used the template?
Thanks in advance!
Jianbin
Edited by Jianbin on 11/01/03 09:54 PM (server time).
JonathonG
Hmm, still not sure that I follow...Are you talking about using Templating or your own custom CGI script? I'm guessing you're talking about TeamSite Templating, in which case, things are pretty simple.
To send data from JavaScript (FormAPI) to your CGI, you use callServer and set up parameters:
// Send data from variable bar to CGI
var parms = new Object;
parms.foo = bar;
IWDatacapture.callServer(pathToYourCGI, parms, true);
Then, your CGI should be able to access the post variable called "foo" and that will give you the value of what was contained in the JavaScript variable "bar". Then, you should note that when callServer is executed, the results are written to a hidden frame, which can access the JavaScript frame via:
parent.top.getScriptFrame();
So, you create a function in your FormAPI script called, for example, setValue:
function setValue(newVal)
{
bar = newVal;
}
Then, you have your CGI create javascript to call this, passing in the new value you want bar to have:
print << EOF;
<html>
<head>
<script>
parent.top.getScriptFrame().setValue($newBar);
</script>
</head>
</html>
EOF
Where, of course, $newBar is your perl variable containing the new value for bar.
DISCLAIMER: This code may not work exactly as-is. This is just used as an example to get you going, you should read up on callServer and formAPI to get the details correct.
HTH,
Jonathon
Independent Interwoven Contractor