Sihal has asked for the wisdom of the Perl Monks concerning the following question:

Fellow monks,

I'm currently writing a script in order to automate a task.
The script connects to a remote website, logs in (I thought that wouild be hard, but it's actually really easy, thanx perl) and does stuff.

My problem is that there is a form I want to act on, that calls a javascript... I have no idea of what to do with the javascript, that is to say how to make it run so that I can fill in my form, and run the javascript to validate my inputs/execute my query.
Any ideas on how to do that?

I can provide more info if needs be.

Replies are listed 'Best First'.
Re: (nrd) LWP || HTML:: Request and Javascripts
by newrisedesigns (Curate) on Nov 05, 2002 at 13:30 UTC

    This might answer your question, or it might compel you to post more code.

    Either figure out what the javascript does (view it in a browser and view the source) and emulate it, or bypass it completely.

    If you only need it for form validation, check the form on your side in Perl, and then post it to the CGI script. You might not need to do anything at all, it depends on what the javascript does.

    Hope this helps,

    John J Reiser
    newrisedesigns.com

      All right now I get it.
      Apparently, the Javascript updates the values of the parent window object (the parent's window form, wich is why I didn't see at first glance how to emulate the behavior in Perl).

      So now that I know how the child frame js behaves, I'm able to emulate it in the parent ... (Dunno if it his clear).
      Well at least now I know that there is a module that enables us to run embedded js code...
        OK, same node, different question:
        I need now to upload a file: that is, I have an input tag, with the "file" type attribute.
        The question being, how do I effectively upload the file? obiviously, if I enter just the path to the file, it won't work... (didn't try though, i'll do right away, what I tried was posting the whole file content)

      Yes it helps... kinda. The trouble is I still faill to understand how that particular JS works, so I cannot emulate it in perl :(.
      For info, there is a module called Javascript that enables you to execute embedded js code in a perl script.
      I'm going to dissect the JS i'm working on before asking more questions, i'll keep you posted.
        If you want to post the JS here I'll take a stab at figuring out what its doing.

        For info, there is a module called Javascript that enables you to execute embedded js code in a perl script. The general consensus on the libwww maiing list seems to be that this doesn't work reliably enough to be worthwhile.

        Dingus


        Enter any 47-digit prime number to continue.
      OK. I have another problem with HTTP::Request::Common.
      This time the problem is that my query always miss 2 characters in the end, that is: %0D%0A (\r\n i reckon).

      I noticed this using ethereal.
      Trouble is, this request is exactly the same as the previous ones, ( except that it's not the same link of course) so I dunno why I have those 2 missing characters..
Re: LWP || HTML:: Request and Javascripts
by fglock (Vicar) on Nov 05, 2002 at 13:29 UTC

    I solved a problem like this by rewriting the javascript part in Perl.

    You don't have to validate your own input, if you know it is right.

    Of course, you will have to change your program whenever the form or the script change.