Need help with Gmail username dropdown script

Subscribe to Need help with Gmail username dropdown script 5 posts, 3 voices

 
Neewb Scriptwright

Hai, Im Neewb. This is a script Im working on for teh Gmail login page.

The first part removes the "username" textbox, and then the second part adds a dropdown with a couple of user IDs for the user to choose.

I just need the help on last line. Can't get it right next to the "Username: " text ??

var txtbx = document.getElementById('Email');
if (txtbx) {
	txtbx.parentNode.removeChild(txtbx);
}

var target = document.getElementById("Passwd");
if (target) {

	var dpdwn = document.createElement('select');
	dpdwn.setAttribute('name', 'Email');
	dpdwn.setAttribute('id', 'Email');
	dpdwn.setAttribute('class', 'gaia le val');
	dpdwn.setAttribute('size', '1');

	var opt = document.createElement('option');
	opt.setAttribute('value', 'john.doe');
	var optxt = document.createTextNode('john.doe');
	opt.appendChild(optxt);
	dpdwn.appendChild(opt);

	var opt = document.createElement('option');
	opt.setAttribute('value', 'jane.doe');
	var optxt = document.createTextNode('jane.doe');
	opt.appendChild(optxt);
	dpdwn.appendChild(opt);

	target.parentNode.insertBefore(dpdwn, target.previousSibling); // ? ? ? ? ?
}

 
Neewb Scriptwright

This script actually already works. I just need the created <select> element right next to the "Username:" text. Right now it shows a space and it looks ugly so its more of a cosmetic issue.</select>

 
Descriptor Scriptwright

Wait, I forgot, I looked at one of my scripts and remembered this:
Instead of removing txtbx, do txtbx.parentNode.replaceChild(dpdwn, txtbx);.
Let me look up a link for that : http://developer.mozilla.org/en/docs/DOM:elemen...
Obviously you do that instead of target.parentNode.insertBefore...

 
JeremyT Scriptwright

how's this for the script?
I added a users variable so adding users is easier via a function called populate. i also changed the width of the select element to be equal to the width of the password input box.

//add users through the array variable
var users = ['john.doe', 'jane.doe'];
var txtbx = document.getElementById('Email');

var target = document.getElementById('Passwd');
if (target) {

	var dpdwn = document.createElement('select');
	dpdwn.setAttribute('name', 'Email');
	dpdwn.setAttribute('id', 'Email');
	dpdwn.setAttribute('class', 'gaia le val');
	dpdwn.setAttribute('size', '1');
	dpdwn.setAttribute('style', 'width:' + target.offsetWidth + 'px');

	function populate() {
		for(var i = 0; i < users.length; i++) {
			var opt = document.createElement('option');
			opt.setAttribute('value', users[i]);
			var optxt = document.createTextNode(users[i]);
			opt.appendChild(optxt);
			dpdwn.appendChild(opt);
		}
	}
	populate();
	
}
if (txtbx) {
	txtbx.parentNode.replaceChild(dpdwn, txtbx);
}

i hope this helped?

 
Neewb Scriptwright

Yeah, good job. Thanks, I credited you guys on the script page.