On Sep 10, 11:46 am, Erwin Moller
<Since_humans_read_this_I_am_spammed_too_m...@spam yourself.com> wrote:
> satish2...@gmail.com wrote:
> > 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
<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...