У меня есть поле ввода, которое позволяет пользователю вводить цену,
<div class = "prc-box"><input type="number" class="form-controle" id="oprc" placeholder="$" name="offerPrice" required="required"></div>
Затем у меня есть форма с несколькими полями, как показано ниже,
<div class ="cash-section" id ="cash-form">
<div class ="input-group-custom" id = "mon-deposit">
<div class = "deposit-input">
<label class="control-label">Earnest Money Deposit Amount (0-50%)</label>
<input type="number" min="0" max="50" class="form-control1" onkeyup="getPrice(this)" placeholder="0-50%" name="moneyDep" required="required"><span class="input-val moneyDep">$0</span></div>
</div>
<div class ="input-group-custom" id = "req-conc">
<div class = "req-input">
<label class="control-label">Requested Concessions (0-60%)</label>
<input type="number" min="0" max="60" class="form-control2" placeholder="0-60%" name="req-conc" required="required"><span class="input-val req-conc">$0</span></div>
</div>
<div class ="input-group-custom" id = "sel-credit">
<div class = "sel-input">
<label class="control-label">Other Seller Credits (0-50%)</label>
<input type="number" class="form-control" placeholder="0-50%" name="sel-credit" required="required"><span class="input-val sel-credit">$0</span></div>
</div>
<div class ="input-group-custom" id = "insp-period">
<div class = "insp-input">
<label class="control-label">Inspection Period (0-60)</label>
<input type="number" class="form-control" placeholder="0-60" name="insp-period" required="required"><span class="input-val insp-period">days</span></div>
</div>
<div class ="input-group-custom" id = "due-section">
<div class = "due-input">
<label class="control-label">Due Dilligence Review Period (0-60)</label>
<input type="number" class="form-control" placeholder="0-60" name="due-section" required="required"><span class="input-val due-section">days</span></div>
</div>
<div class ="input-group-custom" id = "days-count">
<div class = "days-input">
<label class="control-label">Requested # of Days to Closing (0-120)</label>
<input type="number" class="form-control" placeholder="0-120" name="days-count" required="required"><span class="input-val days-count">days</span></div>
</div>
</div>
Предположим, пользователь вводит значение в первое поле ввода цены, скажем, 50000. Затем пользователь вводит значение в поле ввода #insp-period как 10. Теперь мне нужно рассчитать 10% введенной цены (здесь 50000) в первом поле ввода, и он должен отображаться в классе span.
Я попытался сделать то же самое, что и ниже,
function getPrice(price) {
var offerPrice = jQuery('.form-controle').val();
var text1 = price.value;
var result1 = (text1*offerPrice)/100;
jQuery('.input-val.moneyDep').html(result1);
}
Это работает нормально, когда onkeyup="getPrice(this)" вызывается из одного поля ввода. Как я могу заставить его работать и для других полей ввода? Мне нужно вводное значение каждого текстового поля отдельно и начальное значение входной цены каждый раз.
Как я могу этого добиться?
.input-val.moneyDep
? - person Pedram   schedule 11.03.2018onkeyup="getPrice(this)"
для каждогоinput
? вы только что использовали один раз - person Pedram   schedule 11.03.2018form-control1, form-control2
и т. д.? У вас везде разные классы, но вы собираетесь проделать одну и ту же операцию для всех них/ - person Alex Yokisama   schedule 11.03.2018