Question

I have to prevent user to insert letters in numeric fields. I use this:

 $('input[name=myinput]').live('keyup', function() {
                var $th = $(this);
                $th.val($th.val().replace(/[^0-9,\.]/g, ''));
        });

How could I list the other input fields? (I can't use $('input'))

I tried with

$('input[name=myinput],input[name=myinput2]').live('keyup', function() {
                var $th = $(this);
                $th.val($th.val().replace(/[^0-9,\.]/g, ''));
        });

but only input[name=myinput] is accepted.

Was it helpful?

Solution

You should use a class on the input element and then do:

$('input.eKeyup').live('keyup', function() {
    var $th = $(this);
    $th.val($th.val().replace(/[^0-9,\.]/g, ''));
});

OTHER TIPS

Group them in a css class and use $('.className') it's faster and easier.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top