Onkeyup event with Jquery

Asked

Viewed 2,077 times

1

This is what I need to do onkeyup of inputs classy virgula_nao, obey the function:

$(document).on('keyup', '#virgula_nao', function () {
    valor_do_input = valor_do_input.value.replace(/,/gi, ".");}
});

I don’t know how to do it. Someone can help me?

  • Would you like to make a sort of floating-point mask?

  • What’s the problem? What do you want to happen?

  • Explain better what you want to do, what behavior is expected so that we can help.

  • I want that in the form, if the user type , in the various inputs that need to receive value in currency change automatically to point. I can do it with javascript, one input at a time... but I want to create a class of inputs that meet this condition.

2 answers

1

From what I understand, you want to replace the commas with dots in the event keyup, follows an example of how to do with jquery:

$(document).on('keyup', '.virgula_nao', function(e) {
  var keycode = e.which ? e.which : event.keyCode;
  if (keycode == 110 || keycode == 188) {
    e.preventDefault();
    $(this).val($(this).val().replace(",", "."));
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

Input 1: <input class="virgula_nao" /><br><br>
Input 2: <input class="virgula_nao" />

  • Exactly that... Thank you!

0

It would not be better to leave to use a mask plug-in?

You can define a Pattern in the inputs.

Example: $('.money').mask('000.000.000.000.000,00', {reverse: true});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.