Passing a JS var to PERL through SSI.

     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/"-->
Where parent.handle = "bob"
but this doesn't work.

What it should do:
HTML would equal:
Bob's age is <!--#exec cgi='../cgi-bin/'-->
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.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.


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

where myvar is the variable containing "Bob"
cideAuthor Commented:
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.
try replacing the "?" with unescape(%nr) in which nr should be the ascii code for ?


document.write ( "<!--#exec cgi='../cgi-bin/" + unescape(%nr) + myvar + " '-->
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

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=" '+yourvar+'"-->')

this will be equivalent to call from cammand prompt
> 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.

cideAuthor Commented:
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.
cideAuthor Commented:
    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

 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:


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

cideAuthor Commented:
Client Side I'm not sure if my server supports Server Side.
cideAuthor Commented:
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/" but somehow get it not to go to a new page, just write in the current one.  Is this possible?
I guess you working in wrong direction.

Your current process is :
1) user type in userID and password
2) a perl cgi verify the id and pass and return something similar to the following:
   <frameset rows="50%, *">
       <frame name="A" src="pageA">
       <frame name="B" src="pageB">
   and you have already set parent.handle in either pageA or pageB.
3) In pageA or pageB, you want to use SSI to invoke another CGI to get data into the page.

NOTE: If  pageA is generate by a script (the script adding some javascript variable to the page), SSI does not run at all. SSI work only if the web server return a web page to browser directly.

** Passing SSI with javascript is WRONG DIRECTION in this project.
Honestly, you should :
A) insert <!--#exec cgi="../cgi-bin/"-->  directly to the html page, then return the following to the browser.
    <frameset rows="50%, *">
       <frame name="A" src="pageA.html">
       <frame name="B" src="pageB.html">


B) return the following to the browser :
   <frameset rows="50%, *">
       <frame name="A" src="pageA.cgi">
       <frame name="B" src="pageB.html">
   in the program pageA.cgi, you execute and insrt the result to the page, then print out pageA.html to the browser.

   I know the solution is not that easy to do (require you to modify some existing scripts). However, if you still try to play around with the SSI, I bet you never finish this project.I'm sorry to bring this bad news.

Good Luck to you.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day 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!)
cideAuthor Commented:
Sorry, can't decrease points in other question.  Although, this seems to be going nowhere fast.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.