Question

I have a website where we use Javascript to submit the login form. On Firefox it prompts the user to remember their password, when they login, but on IE7 it doesn't.

After doing some research it looks like the user is only prompted in IE7 when the form is submitted via a Submit control. I've created some sample html to prove this is the case.

<html>
<head>
<title>test autocomplete</title>
<script type="text/javascript">
function submitForm()
{
    return document.forms[0].submit();
}
</script>
</head>
<body>
<form method="GET" action="test_autocomplete.html">
<input type="text" id="username" name="username">
<br>
<input type="password" id="password" name="password"/>
<br>
<a href="javascript:submitForm();">Submit</a>
<br>
<input type="submit"/>
</form>
</body>
</html>

The href link doesn't get the prompt but the submit button will in IE7. Both work in Firefox.

I can't get the style of my site to look the same with a submit button, Does anyone know how to get the remember password prompt to show up when submitting via Javascript?

Was it helpful?

Solution

Why not try hooking the form submission this way?

<html>
    <head>
        <title>test autocomplete</title>
        <script type="text/javascript">
            function submitForm()
            {
                    return true;
            }
        </script>
    </head>
    <body>
        <form method="GET" action="test_autocomplete.html" onsubmit="return submitForm();">
            <input type="text" id="username" name="username">
            <br>
            <input type="password" id="password" name="password"/>
            <br>
            <a href="#" onclick="document.getElementById('FORMBUTTON').click();">Submit</a>
            <br>
            <input id="FORMBUTTON" type="submit"/>
        </form>
    </body>
</html>

That way your function will be called whether the link is clicked or the submit button is pushed (or the enter key is pressed) and you can cancel the submission by returning false. This may affect the way IE7 interprets the form's submission.

Edit: I would recommend always hooking form submission this way rather than calling submit() on the form object. If you call submit() then it will not trigger the form object's onsubmit.

OTHER TIPS

Did you try putting in url in the href and attaching a click event handler to submit the form and returning false from the click handler so that the url does not get navigates to.

Alternatively hidden submit button triggered via javascript?

You could try using the HTML <button> tag instead of a link or a submit button.

For example,

<button type="submit">Submit</button>

The <button> tag is much easier to style than the standard <input type="submit">. There are some cross-browser quirks but they are not insurmountable.

A really great article about the use of <button> can be found at particletree: Rediscovering the button element

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top