Fiddle Demo

这是它的JSfiddle,似乎无法获取只读输入来更新其他输入的val(它将是隐藏的输入)

的HTML

<form>
    <input id="otherAmt" class="qty" type="text" placeholder="Amount Hidden" />
    <p> The Costs are:</p> <input type="text" id="otherAmtHidden" name="otherAmtHidden" readonly="" />
</form>

var otherAmt = document.getElementById("otherAmt");

var otherAmtHidden = document.getElementById("otherAmtHidden");

otherAmt.oninput =  function(){
   alert('input Received');
   var val1 = parseInt(otherAmt.value, 10);
   alert(val1 + 'val1');
   var amtHidden = val1;
   alert(amtHidden + 'amtHidden');
   //otherAmtHidden.innerHTML = amtHidden;
   $('input [name="otherAmtHidden"]').val(amtHidden);
   alert('finished');
};


编辑:我很笨,通过将$('input etc').val(amtHidden);更改为$('#otherAmtHidden).val(amtHidden);来解决它

最佳答案

我很笨,我通过更改$('input etc')。val(amtHidden);来解决它。到$('#otherAmtHidden).val(amtHidden);

Fixed Javascript

var otherAmt = document.getElementById("otherAmt");
var otherAmtHidden = document.getElementById("otherAmtHidden");

otherAmt.oninput =  function(){
   var val1 = parseInt(otherAmt.value, 10);
   var amtHidden = val1;
   $('#otherAmtHidden').val(amtHidden);
};

09-30 19:12