Link to home
Start Free TrialLog in
Avatar of cide
cide

asked on

Passing a JS var to PERL through SSI.

Hi,
     I was wondering how I would go about sending a JS variable to a PERL script through SSI.  I've tried:

<!--#exec cgi="../cgi-bin/name.pl?parent.handle"-->
Where parent.handle = "bob"
but this doesn't work.

What it should do:
.
HTML would equal:
Bob's age is <!--#exec cgi='../cgi-bin/name.pl?parent.handle'-->
And the user would se:
Bob's age is 25.

How would I make it show the proper output so far I just get an error.
Avatar of percyn
percyn

I think you need to make JS print out the exec line so that the VALUE of the variable is passed to the CGI, not the variable itself.

e.g.

document.write ( "<!--#exec cgi='../cgi-bin/name.pl?" + myvar + " '-->

where myvar is the variable containing "Bob"
Avatar of cide

ASKER

No, that didn't work.  I did more experimenting with it and the problem seems to be when I add anything after the ? even normal text.
Avatar of sybe
try replacing the "?" with unescape(%nr) in which nr should be the ascii code for ?

so

document.write ( "<!--#exec cgi='../cgi-bin/name.pl" + unescape(%nr) + myvar + " '-->
Hmmm...
Probably in this case exec cgi=  do not set enviroment variables
And do not recognize ?query ...

you can try using cmd instead of cgi like:

document.writeln('<!--#exec cmd="some.pl '+yourvar+'"-->')

this will be equivalent to call from cammand prompt
>some.pl yourvarvalue

but in this case parameter will be passed trough
$ARGV[0] variable :)
and association of perl to .pl extension should be set in system.

Avatar of cide

ASKER

Doesn't solve the prob JavaScript is interprated after SSI.
That what I'm was afraiding of....
Unfortunatly I do not find the way how to set enviroment
variables from Java Script. If this is possible you can pass
it through enviroment.
Last way is to pass through tmp file :(
Not the best solution...



Before anwsering this question, we have to take a look at when the SSI work and when the JavaScript Work.
1) Before the web server send html to browser, ir parse the html and execute all SSI command in the html.
2) Server send the page to web browser.
3) Web Browser execute client side script (javascript) and html.

           Web Server                                           Web Browser
   -------------------------------------------                    --------------------------------------------------------
 |  html  -> execute SSI          |   ----------->   | execute JS, HTML, client side element|
  -----------------------------------------                     ----------------------------------------------------------

Therefore, If you try to pass client side javascript to a SSI, it will 100% fail. (In SSI state,
the web server don't know what is javascript. (except server-side javascript with Netscape server or ASP with microsoft Information Server)
 
However, there is 1 way to pass JS variable to cgi program in a html page.
you can use :
<img src="http://aaa/cgi-bin/myCGI?name=jsVar">
(sure, you have to use document.write() to write out this line with your jsVar)
In this case, your cgi must return a image, not text.

If you can explan your project more detail, likely we can provide you better answer.
Avatar of cide

ASKER

Hi,
    What we are trying to do is setup a login script.  We have it now so a person enters their username and pword into a form and this data is passed to PERL script for verification.  If this data is correct it returns a frameset (which is our main page).  The frameset also stores their handle though, as a JS variable.  We can then access their name whenever we want through parent.handle.  However we are having trouble sending this variable to SSI.  We don't want the user to have to click a submit button in order to run every script and we would also like to generate only part of a page at a time like SSI does.....
Then you are using SSI INCORRECTLY !!!!

If you want to call the perl script and pass it some arguments, try

location.href="/cgi-bin/myperlscript.pl?myvar"
 in Javascript.
Well, Guys, BTW, what JS do you mean, when I answered this question I thought that you mean server-side JavaScript without any doubts, Anguslai in his answer supposed client-side script.
the whole scheme should be:

FILE->SSI(Perl)->ServerSsideJavaScript-->>--ClientJavaScript->HTML

So,Cide, just tell what side JavaScript you mean in question?

Avatar of cide

ASKER

Client Side I'm not sure if my server supports Server Side.
Avatar of cide

ASKER

I think Percyn almost has it except I don't want it to go to a new page.  I want it to append to the current page.  So use location.href="/cgi-bin/myperlscript.pl?myvar" but somehow get it not to go to a new page, just write in the current one.  Is this possible?
ASKER CERTIFIED SOLUTION
Avatar of anguslai
anguslai

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
By the way, why you post this question in perl section with 200 points, but post the same question in JavaScript Section with 100 Points?
Please reduce the point in Perl Section to 150 and increase point to 150 in JavaScript Section. (Unless you think that people who answering question in JavaScript section should earn less!)
Avatar of cide

ASKER

Sorry, can't decrease points in other question.  Although, this seems to be going nowhere fast.