Discussion Locked

Submitting a form thru JavaScript

0 helpful
6 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I am working on a service to programmatically fill in a user's login & password for a website and log the user in.

I am writing JavaScript to fill in the login & password and simulate the user submitting the form, but am facing a problem with forms that use as the Submit button. Strangely, this element does not appear in the form.elements array. Going thru the document.body.all array, I did find the element but it is the 55th element in this array of ~119 elements on the www.go.com login page.

Isn't there an easier way to get the DOM object for this element, and would element.click() work on an element?

Looked thru documentation on Netscape & Microsoft sites, but found no answer.

Thanks in advance...
- EndGoalFreak

6 replies

by jay eckles

element.click() does work on an INPUT type=image...I do it myself in an internal web application.

Easier than trying to find the submission button and programmatically clicking it, why not just use
document.forms[i].submit() ?

To answer yourquestion about finding the DOM object for the element, if it's not in the form.elements array, the only thing I know to look through is document.all. You're already doing everything you can as far as I can tell. But, like I said, form.submit() should really make your life a little easier.

Good luck.

Jay Eckles
www.jayeckles.com

by shanghai sam

I tried both form.submit() and form.all[52].click() (where form.all[52] is the DOM object for the INPUT type=image element); but neither worked. Wonder how click() works for you on such elements.

To make matters worse, the www.go.com login form has a hidden element named "SUBMIT" so I don't know if form.submit would actually refer to this element. Anyway, form.submit() does not work on other login forms, too, even those that DON'T have any other element named "SUBMIT".

Here is my JS code:
function SubmitForm(Win)
{
var formObj = Win.document.loginForm;
formObj.all[52].click(); // HACK to test simulating Submit button on Go.com login page
//formObj.submit();
return true;
}

by endgoalfreak

Now, I find that form.submit() does submit the form. Wonder
why it didn't work earlier. Maybe, my code did not actually
call form.submit() because seeing another form element of type
"hidden" named "submit", the code just returned before gettingto the point of doing form.submit().
Thanks... don't need any more answers.

This discussion is closed to new replies.