Имеется форма:
<input type="text" value="1" size="2" oninput="recalc(2);" name="2"/>
И скрипт:
function recalc(product_id) {
var quantity = $('input[name=\'' + product_id + '\']').val();
var quantity = typeof(quantity) != 'undefined' ? quantity : 1;
var options_price = 0;
$('#option_'+product_id+' option:selected, #option_'+product_id+' input:checked').each(function() {
if ($(this).attr('price_prefix') == '+') { options_price = options_price + Number($(this).attr('price')); }
if ($(this).attr('price_prefix') == '-') { options_price = options_price - Number($(this).attr('price')); }
});
var price_no_format = Number($('.change-price'+product_id).attr('price'));
var special_no_format = Number($('.change-special'+product_id).attr('price'));
var new_price = (price_no_format + options_price) * quantity;
var new_special = (special_no_format + options_price) * quantity;
$('.change-price' + product_id).html(price_format(new_price));
$('.change-special' + product_id).html(price_format(new_special));
}
Как добавить ограничение на минимальное и максимальное число ввода в input?
Делал следующим образом
function recalc(product_id) {
var quantity = $('input[name=\'' + product_id + '\']').val(nquantity);
var nquantity = +$('input[name=\'' + product_id + '\']').val().value.replace(/\D/g,'')||0;
if (value>maximum) value=maximum;
if (value<minimum) value=minimum;
var quantity = typeof(quantity) != 'undefined' ? quantity : 1;
var options_price = 0;
$('#option_'+product_id+' option:selected, #option_'+product_id+' input:checked').each(function() {
if ($(this).attr('price_prefix') == '+') { options_price = options_price + Number($(this).attr('price')); }
if ($(this).attr('price_prefix') == '-') { options_price = options_price - Number($(this).attr('price')); }
});
var price_no_format = Number($('.change-price'+product_id).attr('price'));
var special_no_format = Number($('.change-special'+product_id).attr('price'));
var new_price = (price_no_format + options_price) * quantity;
var new_special = (special_no_format + options_price) * quantity;
$('.change-price' + product_id).html(price_format(new_price));
$('.change-special' + product_id).html(price_format(new_special));
}
Не получилось. Подскажитеак выполнить такую обработку?