1

I am having trouble with manual form submission with javascript in Firefox and IE. There are no problems in Chrome and Opera.

As the user submits form, I intercept it with javascript/jquery, hash the password and resubmit the form.

I have tried many alternate variations using only javascript which also dont work.

Also the problem is this specific code because without it, it works perfectly.

 window.onload = main;


function main()
{                                           // Problem with Firefox and IE
                                            // Form seems to not submit correctly after the manual submit
 $('#loginForm').submit(function(event) 
    {
        if (typeof event.originalEvent !== 'undefined') 
        {
            event.preventDefault();
        }
        else
        {
            return;
        }


        var passHash = CryptoJS.SHA256($('#password').val());
        $('#password').val(passHash.toString());

     //   document.getElementById('loginForm').submit();
        $('#loginForm').trigger('submit');
    });  
}
Liam
  • 27,717
  • 28
  • 128
  • 190
VOid
  • 85
  • 2
  • 13
  • You should use [ready](http://api.jquery.com/ready/) not attach onload. Not sure if this is the route cause of your problem though? – Liam Jan 30 '14 at 10:25
  • It's not [this issue](http://stackoverflow.com/a/4169636/542251) is it? – Liam Jan 30 '14 at 10:28
  • I'm not sure, didn't tested out but, aren't you looping on submit event with this script ? Imo you should remove the `preventDefault()` simply to you your stuff and then `return true` to send the form or `return false` to not send it. – Gregoire D. Jan 30 '14 at 10:29
  • With window.ready it does actually submit but the hashing seems to not work then as the server outputs invalid username/password – VOid Jan 30 '14 at 10:31

1 Answers1

0

Too complex, it only needs:

function main()
{                                           

    $('#loginForm').submit(function(event) 
    {

        var passHash = CryptoJS.SHA256($('#password').val());
        $('#password').val(passHash.toString());

        return true;
    });  
}
Axel Amthor
  • 10,980
  • 1
  • 25
  • 44