views:

2750

answers:

4

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?

+1  A: 

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?

Sijin
+4  A: 

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.

Zack Mulgrew
+1  A: 

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

Adz
A: 

I'm trying to do something like this with ASP.NET Forms Authentication with Web Forms. I have an AJAX web service and I can get authenticated through that fine - but of course the browser never asks to remember the user's username and password.

Simply doing a submit on a page doesn't seem to make the browser offer to remember the username/password.

I have tried this: http://stackoverflow.com/questions/158438/ie7-form-not-prompted-for-remember-password-when-submitted-through-javascript but I can't make myself a form because I'm using Web Forms - so it's already in one.

Any ideas on how this could work with Web Forms?

Ian Grainger
Managed this with a horrible hack by having an invisible asp:login control and using jQuery to submit using that once i've checked that the login's going to work.Yuk.
Ian Grainger
Ah, I assume I had to submit using the login control because my jQuery dialog textboxes are added outside of the asp.net form, so adding that dialog to the right form will probably fix my problem.
Ian Grainger