Safari, javascript and a button - help!

Hello,

i am trying to get Applescript to fill out a web form, POST data.

The form has several elements, including some checkboxes, and some buttons to be clicked AFTER a checkbox is checked.

I have figured out how to “do Javascript” and get the right checkboxes checked in Safari:

do JavaScript “document.forms[0].elements[8].checked=true” in document 1

now I am trying to click a button after checking the correct box. It should give me a new webpage, based on which checkbox I picked.

I have tried:

do JavaScript “document.forms[0].elements[7].onclick()” in document 1

But, it doesn’t work. the browser doesn’t appear to respond at all.

Something is weird that I don’t understand, because:

This IS the correct element to click.
If I do not have any checkbox checked, this same Applescript command DOES give a response - it tells me that I need to have a checkbox checked!

It appears that clicking the button with the ‘do Javascript’ works only under the situation that no checkbox is checked, which doesn’t get me where I want to go. What am I missing?

many thanks!
John

John Fowler
Oregon State University

Is there something else going on in the page’s javascript? Is that just a plain submit button, or does it have an onclicked event defined to do something else? If there’s an onclicked event for the button, can you change it so the first thing it does is throw up a message or display an element so you know for sure that it’s receiving the event you’re sending from the applescript?

The problem is that you need to click(), NOT onclick(). The method onclick() in JavaScript is the function built into the page’s JavaScript that runs when someone clicks the button. You want:

do JavaScript “document.forms[0].elements[7].click()” in document 1

What you were doing before was telling the page: “Hey! Run the little verification script that happens when I click the button, but don’t bother actually clicking the button.” That’s why you got that “you need to check a checkbox” message. One interesting comment to go with that - if you want to try to submit the form without it running that verification function (aka onclick() ), you could try running:

do JavaScript “document.forms[0].submit()” in document 1

I don’t know if that would cause problems for the server, since it is expecting that the form will be verified to have proper selections by the onclick() function.