JS Login form autofill script problem

Attempt to get a JS autoformfill to work for a website login

Page 1 of 1

1 Replies - 1971 Views - Last Post: 05 March 2009 - 09:53 PM

#1 aaron.t.small  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 17-January 09

JS Login form autofill script problem

Posted 04 March 2009 - 11:55 PM

I am trying to automate a login to a website and am learning jscript on the fly :P

java script:
var webstart ={
	var email = prompt('Enter your Email Address:', 'Email...');
	var pwd = prompt('Enter your Password:', 'Password...');
	login: function() {
		var emailtxt = document.GetElementByID('username');
		var pwdtxt = document.GetElementByID('password');
		getemailtxt: function() {
			if (!emailtxt.value) {
				emailtxt.value = email;
			return username.emailtxt;
		getpwdtxt: function() {
			if (!pwdtxt.value) {
				pwdtxt.value = pwd;
			return password.pwdtxt;

It would be nice to get some help with this, I am currently trying to sort this out and then I'll be trying to use JS & PHP to navigate and autoformfill on a site, so sorting out this basic stuff is kinda important :P

When I attempt to run this in Firebug, I get this error:


SyntaxError: missing : after property id

PS I did use your search engine but I got no results - so please be gentle with the flames :blink:


Is This A Good Question/Topic? 0
  • +

Replies To: JS Login form autofill script problem

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4930
  • View blog
  • Posts: 13,327
  • Joined: 18-April 07

Re: JS Login form autofill script problem

Posted 05 March 2009 - 09:53 PM

I am not quite sure where you got all that but it has some serious problems in its structure. It appears to be JSON object building but then again it is not. Probably why Javascript is having a big question too. Here is something that you can work off of...

<script language="Javascript">
// Create a webstart object
var webstart ={
    // Prompt at page start for email and password
    email: prompt('Enter your Email Address:', 'Email...'),
    pwd: prompt('Enter your Password:', 'Password...'),
    emailtxt: null,
    pwdtxt: null,

    // Login function gets the fields, then loads them with values from the webstart object properties.
    login: function() {
		this.emailtxt = document.getElementById("username");
		this.pwdtxt = document.getElementById("password");
		this.emailtxt.value = this.getemailtxt();
		this.pwdtxt.value = this.getpwdtxt();
    getemailtxt: function() {
		// Return this objects email when asked
		return this.email;
    getpwdtxt: function() {
		// Return this objects password when asked
		return this.pwd;

Must call webstart.login here or through a specific control handler because we need to make sure input
controls username and password below have actually been loaded first

<body onload="webstart.login()">

<form method="GET" action="test.htm">
First Name: <input type="text" name="username" id="username" />
<br />
Last Name: <input type="text" name="password" id="password"/>
<br /><br />

<input type="submit" value="Submit"/>


Upon loading the page, you are asked the username and password. Filling those in will store that info inside our webstart object.

When the page finishes loading, it will call the onload event which calls our objects login method. There it will get the two input controls using getElementById (notice the capitalization... javascript is case sensitive). It will then call the two other methods getemailtxt and getpwdtext and fill those controls with the values entered earlier.

You could call webstart.login also from a button onclick handler or another type of handler for a control. You just have to make sure that the input controls referenced in the webstart object have actually been loaded first. You can't fill something that has yet been created.

Hope this is what you were looking for... or at least close to it.

"At DIC we be webstart creating code ninjas... we are also the masters at the finish. That would be the part where our enemies have fallen and we are standing." :snap:

This post has been edited by Martyr2: 05 March 2009 - 09:53 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1