views:

57

answers:

2

This works flawlessly under Chrome, but in Firefox the fields don't populate until the SECOND time I hit submit on the page (after it comes back from the first time telling me invalid user/pass). What am I missing?

This is my code for the Greasemonkey script:

document.getElementById('loginBtn').addEventListener('click',
function (event) {
    document.getElementById('serverLogin').selectedIndex = "2";
    document.getElementById('usernameLogin').value = "username";
    document.getElementById('passwordLogin').value = "password";
    document.getElementById('loginForm').action = 'urltosubmit';
    location.href="javascript:(function(){ document.forms['loginForm'].submit(); })()";
},true);
A: 

You should post your form code, but the problem is most likely, event propagation.

Change the function to:

document.getElementById('loginBtn').addEventListener('click',
function (event) {
    document.getElementById('serverLogin').selectedIndex = "2";
    document.getElementById('usernameLogin').value = "username";
    document.getElementById('passwordLogin').value = "password";
    document.getElementById('loginForm').action = 'urltosubmit';
    location.href="javascript:(function(){ document.forms['loginForm'].submit(); })()";

    event.preventDefault();
    event.stopPropagation();
    return false;
},true);
Brock Adams
A: 

or maybe...

document.getElementById('loginForm').addEventListener("submit", function(e)
{
    var fields = e.target.elements;
    fields.namedItem("serverLogin").selectedIndex = 2;
    fields.namedItem("usernameLogin").value = "username";
    fields.namedItem("passwordLogin").value = "password";
    e.target.setAttribute("action", "urltosubmit");
}, false);
w35l3y