I want to format with comma a number what a value of input. But, This code is not working. jquery version is 3.6.0.
$(function(){
$('.bid_btns_add button').on('click',function(){
var current_value = parseInt($('#bid_price').attr('value'));
var add_value = parseInt($(this).val());
var total_value = current_value + add_value;
var output_value = total_value.replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,"); //error
var output_value = total_value.toLocaleString(); //error
$('#bid_price').attr('value', output_value);
});
$('.bid_btn_clear').on('click',function(){
$('#bid_price').attr('value',0);
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.0/jquery.min.js"></script>
<div class="bid_btns_add">
<button type="button" class="" value="1000">1000</button>
<button type="button" class="" value="5000">5000</button>
<button type="button" class="" value="10000">10000</button>
</div>
<input id="bid_price" type="number" class="input_price" value="0"></input>
<button type="button" class="bid_btn_clear">x</button>