views:

30

answers:

2

HTML5 gives us some new input elements to play with, such as <input type=number>. This renders (in Chrome) as a textbox with two cycle buttons inside the textbox, for incrementing and decrementing the numeric value inside the box.

For a personal hobby project, I'm using this control. However, I'm stuck with one issue:

Is there a way to detect the value being changed using a javascript event? I had expected the onChange event to fire, but no such luck. Also, onClick only triggers when the textbox content is clicked, not when the cycle buttons are clicked.

Any ideas? (apart from: hey, it's HTML5 Forms, don't expect anything to work yet!)

Edit: As mikerobi points out below, the onChange event does fire as soon as the element loses focus. Still not quite what I'm looking for, so other comments and suggestions are welcome!

+3  A: 

The onChange event gets fired when when the box loses focus, but you probably already know that.

The HTML5 specifies that a number input should be a text box or spinner control, but the spec does not appear to have any guidelines for how a spinner should look or behave, leaving those decisions up to the browser vendors.

It appears that in the Mac Safari, the spin buttons do respond to click events, you might want to file a Chrome bug report, I suspect it was just an oversight.

mikerobi
Hi Mikerobi - yeah, should have added that I found the change-on-blur thing already.. thanks for mentioning it though. I'll go file that bug report, thanks!
kander
Which Safari are you using? Mine (5.0.2 on Windows) doesn't support the number type at all, and renders it as a plain textbox :/
kander
@Kander, 5.0.2 on a Mac.
mikerobi