0
<form action="http://google.com">
  <input type="submit" onclick="javascript:this.disabled='disabled';return true">
</form>

It works in Firefox, but not in IE8, Safari (It should forward me to Google's site, it but doesn't happen.). Why?

Gert Grenander
  • 16,866
  • 6
  • 40
  • 43
wamp
  • 5,789
  • 17
  • 52
  • 82
  • 2
    When you say it doesn't work, what do you mean. What error message is in the console. Or what behaviour are you seeing. – thomasrutter Aug 09 '10 at 02:28
  • Possible duplicates: http://stackoverflow.com/questions/840742/disable-a-button-on-click http://stackoverflow.com/questions/106509/disable-button-on-form-submission – Adam Neal Aug 09 '10 at 02:49

2 Answers2

3

You don't need the javascript: pseudoprotocol. This should work:

onclick="this.disabled=true"

and you don't need to return true, that'll happen automatically.

Rafael
  • 559
  • 4
  • 12
3

Try this instead:

<input type="submit" onclick="this.disabled='disabled';form.submit()">

Edit: Added form. as per wamp's comment.

Gert Grenander
  • 16,866
  • 6
  • 40
  • 43
  • I'm not sure, but it seems to be something with IE's implementation of JavaScript. – Gert Grenander Aug 09 '10 at 02:59
  • 1
    Probably more accurately, it's likely a problem with IE's implementation of the *DOM*. Or maybe this is relying on an extension, because I don't remember any global `submit` functions. – strager Aug 09 '10 at 03:05
  • In some cases, I need `form.submit()`, simply `submit` will get an error saying "Object expected",strange.. – wamp Aug 09 '10 at 03:09
  • @strager,you are right,the global `submit` doesn't work in my application,but works in this simplified example,this is strange.. – wamp Aug 09 '10 at 03:10
  • @wamp - `submit()` only worked when I tested it, but just to be on the safe side, I added the `form.` from your comment. – Gert Grenander Aug 09 '10 at 03:21
  • @strager - I tested it in IE 8, Firefox and Iron. Anyway, I've changed the code in my example above. – Gert Grenander Aug 09 '10 at 03:22