Archive

Posts Tagged ‘javascript’

d(this).data(“draggable”) is undefined. Bug on destroying jQuery UI’s draggable/selectable.

September 30th, 2011 Comments off

Only one right silution: to add timeout for 1ms before destroying the jQuery UI’s draggable/selectable

Source: Bug on destroying jQuery UI’s selectable. | Lost in IT world.

 

Categories: JavaScript Tags: ,

jQuery filter user input

June 20th, 2011 Comments off

I’ve coded small function that allows filter user input to <input> fields.
It allows to press 0-9 keys (incl. NumPad keys), “,” and “.”, Backspace.
It’s enought to write float value.

$(':input.onlynum').keypress(function(event) {
    if (
        // numbers
        (event.which < 48 || event.which > 57) && 

        // .,
        event.which != 44 && event.which != 46 && 

        // backspace
        event.which != 8                      
    ) {
        event.preventDefault();
        return;
    }
})

HTML:

Try to input non-numeric symbols:
<input class="onlynum">
Categories: JavaScript Tags: ,