Using javascript variable value in Perl script

Discussion in 'Javascript' started by satish2112@gmail.com, Sep 10, 2007.

  1. Guest

    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.
     
    , Sep 10, 2007
    #1
    1. Advertising

  2. Erwin Moller Guest

    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
     
    Erwin Moller, Sep 10, 2007
    #2
    1. Advertising

  3. shimmyshack Guest

    On Sep 10, 11:46 am, Erwin Moller
    <> wrote:
    > 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...
     
    shimmyshack, Sep 10, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Wet Basement
    Replies:
    1
    Views:
    2,543
    BobMonk
    Jul 15, 2003
  2. dpackwood
    Replies:
    3
    Views:
    1,829
  3. pj
    Replies:
    3
    Views:
    300
  4. vikrant
    Replies:
    4
    Views:
    286
  5. Replies:
    3
    Views:
    214
    The Natural Philosopher
    Sep 4, 2007
Loading...

Share This Page