View Full Version : Auto Submitting form Bookmarklet

08-07-2006, 05:16 PM
I have read a few forums on this but can't seem to get my bookmarklet to do what I want. I want it to act as a bookmark, bringing me to a page. (in my case myspace) then to fill in the fields. (IE - email, password) and lastly, submit it. That way I can just click the link once, and I'm logged in. I have a half working bookmarklet here:

javascript:location.href='http://www.myspace.com';(function(){ var error = 0; var keepError = 'I tried my best, but I was unable to fill in your form perfectly.<br><br>'; var formsArray = content.document.getElementsByTagName('form');try{ formsArray[1]['email'].value='EMAIL@EXAMPLE.COM'; } catch(e){ error = 1; keepError = keepError + '- Form field email could not be found.<br>'; } try { formsArray[1].password.value='PASSWORD'; } catch(e){ error = 1; keepError = keepError + '- I can\'t set focus on the password field password.<br>'; } if(error == 1){ var newwin = window.open('', 'formsaver', 'HEIGHT=250,WIDTH=600,resizable=1,scrollbars=1'); newwin.document.writeln(keepError); newwin.document.close(); newwin.focus(); } })()

(there is also an error checker in there which is not needed, nor part of the problem.)

The problem with this is it will bring me to the page, but won't fill in the form. If I remove "location.href='http://www.myspace.com';", and use the bookmarklet whilst in the page, it will fill in the forms no problem. And from there, I have no idea how to auto submit it. I have been reading up on javascript only for the past 24 hours... so I am new to this. However, I have dabbled more so in programming and html. So I understand what's going on for the most part. Any help with this would be great!!!

08-07-2006, 09:10 PM
There will be a timing problem. The bookmarklet should wait for the form to be fully loaded before submitting it. But the bookmarklet can't use window.onload while using location.href. So you can't have a script that will always work as intended. The alternative solution is to use GreaseMonkey scripts for Firefox (http://greasemonkey.mozdev.org/) or IE (http://www.google.com/search?q=greasemonkey+for+IE).

08-07-2006, 11:31 PM
Is there a way I could Jimmy it to use perhaps a timeout function? And I'm running Firefox, and I've heard a lot about Greasemonkey, so I'll read up on that too. Thanks for the help.

08-08-2006, 06:45 AM
You could use a timeout function but it will not work all the time as pages don't load with constant time. The page might load fast and your script will still wait till the timeout expires before it does something in the form. Or the page might load very slow and the script timeout already expires before the page has completely loaded. So just use Greasemonkey scripts, it has more control of the page than using bookmarklet. It's as if the user script is really included in the page so you can virtually do anything in it as normal scripts do.

08-08-2006, 09:01 AM
Ok, got it installed. Seems like a pretty neat program. Thanks for the tip. Now I just need to fiddle with it a bit to get the hang of things. And oh yeah, learn javascript. :-P Filling a form shouldn't be too hard. I don't think... ??? lol. thanks again