nishanthi nishanthi -3 years ago 80
jQuery Question

How to increment the counter value when the input field is filled?

This is my

laravel
view code. Here,I am trying to increment the counter value(ie.,value="0/5") . I have the input fields inside the modal and when clicking on the save button which is inside the model, the value should get incremented based on the filled input fields.ie(1/5..2/5..)

I have tried to increment those counter value.But it displays NaN



var val;
$("input").click(function() {
val = $('#counter').val();
val++;
$('#counter').prop('value', val)
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="panel-title pull-left">
<i class="fa fa-check-circle" style="font-size:20px;color:lightgreen">
</i> Price,stock and Shipping Information<input type="submit" id="counter" value="0/5" style="background-color: transparent; border:none">
</div>




Answer Source
<script type="text/javascript">
    $("input").click(function() {
        let val = parseInt($('#counter').val().split('/')[0]);
        $('#counter').prop('value', `${++val}/5`);
    });
</script>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download