Donald T
Donald T

Reputation: 10667

IE incorrectly treats HTML <button> as submit button

I have two HTML buttons; one submits a form and one closes the container dialog. The button closing it doesn't have a type attribute:

<button type="submit">Submit</button>
<button class="closeDialog">Close</button>

The JavaScript is as follows:

$(".closeDialog").live("click", function(event) {
  event.preventDefault();
  $(this).parents(".dialog").dialog("close");
});

$("form.myClass").live("submit", function(event) {
  event.preventDefault();
  // submits the form here . . .
});

All of this works well in every browser but IE. In IE, when one clicks the "Close" button, both JavaScript events above execute, but only the .closeDialog event handler should.

IE seems to treat a element as a submit button, regardless of its type attribute.

How can one get around this misinterpretation in IE?

Upvotes: 1

Views: 302

Answers (2)

Sam Sussman
Sam Sussman

Reputation: 1045

Try:

<input type='button' />

This will work with IE in most cases.

Upvotes: 0

Indranil
Indranil

Reputation: 2471

On the second one, try : <button type="button">

Upvotes: 5

Related Questions