Jefferson Vasconcelos Jefferson Vasconcelos - 16 days ago 7
Javascript Question

While typing in a text input field, print content replacing dots

I need rewrite the content of some input into another using 'onkeyup' and replacing the '.' (dots) os the values. Right now, just onkeyup feature of my code runs. How can I do for delivery a 'clear' string (without dots) to another input?

My code:

<script type="text/javascript">
$(document).ready(function(){
var minValue = $('money-min-value');

minValue.onkeyup = function(){
var clearMinValue = '';
clearMinValue = minValue.replace(/[^a-zA-Z 0-9]+/g,'');
$('meta_property_sell_price1').value = clearMinValue;
}
});
</script>

Answer

Does it fix?

jQuery(document).ready(function($) {

  $('#money-min-value').on('keyup',function() {
    var clearMinValue = '';
    clearMinValue = $(this).val().replace(/[^a-zA-Z 0-9]+/g, '');
    $('#meta_property_sell_price1').val(clearMinValue);
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<label>#money-min-value <input type="text" id="money-min-value" ></label><br>
<label>#meta_property_sell_price1 <input type="text" id="meta_property_sell_price1" ></label>

Comments