... I'm trying to use the Scripter class eval method to actually run the code....

You shouldn't have to do that :) any onsubmit or onclick functions should be called by virtue of using a javascript plugin, when you use the submit method

Like the docs say, WWW::Scripter is a subclass of WWW::Mechanize

#!/usr/bin/perl -- use strict; use warnings; use URI; use WWW::Scripter; Main( @ARGV ); exit( 0 ); sub Main { my $w = WWW::Scripter->new( autocheck => 1, show_progress => 1, # prints to stderr ); $w->use_plugin('JavaScript'); #~ $w->add_handler("request_send", sub { shift->dump; return }); #~ $w->add_handler("response_done", sub { shift->dump; return }); $w->timeout(0.00000000001); for my $return ( qw/ false true / ) { warn "BowlingRETURNVALUE => $return \n"; $w->get( data_url($return) ); $w->submit; #~ $w->submit_form( #~ form_number => 0, #~ fields => { qw' user_choice Enter ' }, #~ ); } } BEGIN { my $html = <<'HTML'; <html> <head> <title> localhost form </title> <html> <script type="text/javascript"> function Bowling(){ alert("\nStrike\n"); /* prints to stdout */ return BowlingRETURNVALUE; } </script> </head> <body> <base href="http://localhost/"> <form method="POST" action="http://localhost/" onsubmit="return Bowli +ng();">> <input id="enterbutton" type="submit" name="user_choice" value="Enter" + /> <input type="submit" name="user_choice" value="Leave" /> </form> </body> </html> HTML sub data_url { my $return = shift; my $h = $html; $h =~ s/BowlingRETURNVALUE/$return/; my $u = new URI 'data:'; $u->media_type('text/html'); $u->data( $h ); return $u; } } __END__

As you can see from the log below, first submit doesn't trigger http activity because the onsubmit javascript returns false, but the next one does , because onsubmit callback returns true

Since I don't have a server on localhost, the timeout causes an almost instant internal 500 error -- everything is working as expected

BowlingRETURNVALUE => false ** GET data:text/html;base64,PGh0bWw+ID...Pgo= ==> 200 Document follow +s Strike BowlingRETURNVALUE => true ** GET data:text/html;base64,PGh0bWw+ID...+Cg== ==> 200 Document follo +ws Strike ** POST http://localhost/ ==> 500 Can't connect to localhost:80 (timeo +ut) Error POSTing http://localhost/: Can't connect to localhost:80 (timeou +t) at C:/perl/site/5.14.1/lib/WWW/Scripter.pm line 598

In reply to Re: How do I call a JavaScript function from WWW::Scripter? by Anonymous Monk
in thread How do I call a JavaScript function from WWW::Scripter? by bbrelin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.