Link to home
Start Free TrialLog in
Avatar of robinz
robinz

asked on

Perl, and a little javascript too.

Can I use "Content-type: text/html" to output html to the browser, use a javascript prompt to get info from the user, and then reference that javascript variable from my Perl code?  This is messing with my head, please help.
Avatar of martinag
martinag

You can't use it in the same process of the script that is printing the page.

However, you can recall the script when you've got what you need:
<SCRIPT LANGUAGE="JavaScript">
<!--
s = prompt("Enter something.","");
if (s)
  location.href = location.href + ((location.href.indexOf('?')==-1) ? "?" : "&") + "variableName=" + escape(s);
// -->
</SCRIPT>

This will call the script again and pass the variable to it.

Martin
I haven't tried using Javascript to gather the variable name but you might want to try using the "Content-type: text/html" command to write a page with a form submission, the call a second Perl program from  the newly created code.

For example:  

print" <FORM method=\"POST\" action=\"services.pl\" name="\forma\"><SELECT name=\"season\" size=1><OPTION>Choose
a Main Topic&nbsp;";

This will start a form in Html, which when the submit button is hit it will call the Perl program services.

Like the others said, it's not possible to do what you asked, and an alternative would be to call a second Perl script. Here's why you can't do it:

HTTP works in single, separate transactions. The browser asks for the page, the server gives it one. End of transaction. The next time the user hits a link is whole new transaction; the browser asks for the page, etc. When the link is a CGI, it works like this: the browser requests the CGI link, the server runs the CGI program, the server sends the browser the CGI's output.

Once the browser gets the results from the CGI, the only way it can communicate back to it is to make a whole new request. So, since your Perl CGI runs on the server, and Javascript runs in the browser, it can't be done.

What are you trying to do? Could it be possible to request this information from the user before the CGI is called -- from the previous form?

Yuval




ASKER CERTIFIED SOLUTION
Avatar of sdjjm
sdjjm

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
Avatar of robinz

ASKER

I have large testicles