Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replacing characters using jQuery

Tags:

jquery

I'm trying to remove commas from all of my textboxes on keyup. I came up with the script below but it's not working. Can anyone see what I am doing wrong?

<script>
    $("input[type='text']").keyup
    (
        function () 
        {
            alert('1');
            $(this).val($(this).val().replace(/[,]/g, ""));
        }
    );
</script>

NOTE: please excuse the $ in Script. SO won't let me post it otherwise...

like image 589
Abe Miessler Avatar asked Sep 07 '10 18:09

Abe Miessler


1 Answers

You might want to wrap that whole chunk of code in a document ready function

$(function() {
  $("input:text").keyup(function() {
        $(this).val($(this).val().replace(/[,]/g, ""));
  });
});

You can read all about this on the jQuery documentation site.

like image 172
jessegavin Avatar answered Nov 06 '22 13:11

jessegavin