Using javascript variable value in Perl script

S

satish2112

I'm new to CGI and javascript.

I have a javascript variable which has a value assigned.

function UpdatePage()
{
var x=document.form100.TextArea1.value;
}

I want to use this value in perl script.

$input_string = "var"; - is this possible?

I know a way we can do - using form and submit action to pass the
javascript variable to the perl script.
Is there a way I can avoid using a click of button as an intermediate
step.(So that it is done in the backend and the same page exists)
Passing the value as a query string has a restriction of 1024
characters. I have content which
could be 3000 characters or more.
 
E

Erwin Moller

I'm new to CGI and javascript.

Welcome. :)
I have a javascript variable which has a value assigned.

function UpdatePage()
{
var x=document.form100.TextArea1.value;
}

I want to use this value in perl script.

$input_string = "var"; - is this possible?

Not directly.
What happens in Javascript is not known to your Perl script on the
server, unless you make it known to the server.

I know a way we can do - using form and submit action to pass the
javascript variable to the perl script.

That would be the most straightforward way to pass it to the server indeed.
Is there a way I can avoid using a click of button as an intermediate
step.(So that it is done in the backend and the same page exists)
Passing the value as a query string has a restriction of 1024
characters. I have content which
could be 3000 characters or more.

Yes there are other ways, mainly AJAX.
AJAX let you create an XMLhttpRequest-Object (whatever it is named in
different browsers). You can use this Object to post whatver you want to
a script, AND receive the response.

Read more here for a great hands-on introduction:
http://www.w3schools.com/ajax


And about the 1024 character limitation: I think you won't find a modern
webserver that holds this limit anymore.
But you can use POST too of course via AJAX, just to be sure.

Regards,
Erwin Moller
 
S

shimmyshack

Welcome. :)







Not directly.
What happens in Javascript is not known to your Perl script on the
server, unless you make it known to the server.




That would be the most straightforward way to pass it to the server indeed.


Yes there are other ways, mainly AJAX.
AJAX let you create an XMLhttpRequest-Object (whatever it is named in
different browsers). You can use this Object to post whatver you want to
a script, AND receive the response.

Read more here for a great hands-on introduction:http://www.w3schools.com/ajax

And about the 1024 character limitation: I think you won't find a modern
webserver that holds this limit anymore.
But you can use POST too of course via AJAX, just to be sure.

Regards,
Erwin Moller

<script type="text/javascript">
var x=document.form100.TextArea1.value;
document.write( '<img src="/path/to/script.pl?x='+x+'" />' );
</script>

even better would be to use DOM manipulation instead of document.write
and use a perl script diguised as a jpeg:

'<img src="/path/to/perl_script.jpg?x='+x+'" />'
which returns a normal jpeg, so that the web bug is not noticed. (you
will have to send no cache headers to force the joeg to be requested
from the server each time)

even better than that would be to use rewrites so that the data is not
sent as a get parameter.
'<img src="/path/to/'+x+'/perl_script.jpg" />'

You could also use frames etc.. etc...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top