You can use data-attribute
here and change its value to true
or false
depending on which input is focus . Then ,whenever button is clicked check where is data-focus="true"
and add number to that input.
Demo Code :
$('.frm-control-input').click(function() {
//add data-focus true
$(this).attr("data-focus", true);
//remove from other
$(".frm-control-input").not(this).attr("data-focus", false);
});
$('.btn').click(function() {
var number = $(this).val();
//add value to input where data-focus is true
$('input[data-focus=true]').val($('input[data-focus=true]').val() + number);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="text" class="frm-control-input" name="multi">
<input type="text" class="frm-control-input" name="price">
<button type="button" class="btn" value="1">1</button>
<button type="button" class="btn" value="2">2</button>
<button type="button" class="btn" value="3">3</button>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…