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

Using WWW::Mechanize, how would I trip the onChange attribute in an <select> input? The relevant HTML is below.
<form name="someForm" id="someForm" method="POST"> <select name="foo" onChange="someForm.submit()"> <option value="1">First Option</option> <option value="2" SELECTED>First Option</option> </select>

------
We are the carpenters and bricklayers of the Information Age.

Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

Replies are listed 'Best First'.
Re: WWW::Mechanize and JS onClick attributes
by Corion (Patriarch) on Jan 22, 2004 at 17:37 UTC

    WWW::Mechanize does not have any DOM or Javascript facilities, so you have no other choice but to look at the Javascript yourself and emulate what the Javascript does in Perl.

    If you're adventurous, you could look at what the CPAN has to offer on the topic, and use one of these solutions as basis. But you will still have to implement the browser DOM, which is quite some task to do properly.

    perl -MHTTP::Daemon -MHTTP::Response -MLWP::Simple -e ' ; # The $d = new HTTP::Daemon and fork and getprint $d->url and exit;#spider ($c = $d->accept())->get_request(); $c->send_response( new #in the HTTP::Response(200,$_,$_,qq(Just another Perl hacker\n))); ' # web
Re: WWW::Mechanize and JS onClick attributes
by Mr. Muskrat (Canon) on Jan 23, 2004 at 04:04 UTC

    If I knew that the form had an action associated with it (which is not evident in the snippet you provided), I'd tell you to just have WWW::Mechanize set the value of foo to that of one of the two possible values and then submit the form.

      If I knew that the form had an action associated with it (which is not evident in the snippet you provided)...

      OT, but FWIW: if an HTML form tag does not include an action attribute, it defaults to being the same as the URL where the form was found.