A <button> is not a button

by Jon Davis 7. November 2008 10:46

This just bit me. I always figured that a <button>text</button> tag was the same as an <input type="button" value="text" />. This is not the case, depending on the browser.

While in IE <button>text</button> is treated as <input type="button" value="text" />, in Google Chrome and I believe in FF3, <button>text</button> is treated as <input type="submit" value="text" />. Which means that if you've been using <button onclick="..">text</button> as a way to javascript-up your user interface, and you're not decorating it with a type=".." attribute, you'll get some *cough* unexpected results.

... Results like the whole form getting submitted without your programmatic permission!! Arrrgh.

So to fix that, just get used to writing up the HTML with: <button type="button" onclick="..">text</button>. It's more markup but it's the proper way. Sucks for a bit, and then life goes on. Kinda like our economy, so I keep telling myself.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Add comment

(Will show your Gravatar icon)  

  Country flag

  • Comment
  • Preview


Powered by BlogEngine.NET
Theme by Mads Kristensen

About the author

Jon Davis (aka "stimpy77") has been a programmer, developer, and consultant for web and Windows software solutions professionally since 1997, with experience ranging from OS and hardware support to DHTML programming to IIS/ASP web apps to Java network programming to Visual Basic applications to C# desktop apps.
Software in all forms is also his sole hobby, whether playing PC games or tinkering with programming them. "I was playing Defender on the Commodore 64," he reminisces, "when I decided at the age of 12 or so that I want to be a computer programmer when I grow up."

Jon was previously employed as a senior .NET developer at a very well-known Internet services company whom you're more likely than not to have directly done business with. However, this blog and all of jondavis.net have no affiliation with, and are not representative of, his former employer in any way.

Contact Me 

Tag cloud


<<  March 2021  >>

View posts in large calendar