Моя проблема проста, не такая длинная, как выглядит.
У меня есть 7 текстовых полей с идентификаторами text1, text2, text3, text4 и text5, text6, text7 и один флажок с проверкой идентификатора.Я получаю значение text1 и text2 от JSON как 10 и 20 и вытесняю итоговое значение 30 в text7.Значения text4, text5 и text6 являются пустыми, то есть в этих текстовых полях отображается «0».text3 и text4 будут автоматически заполняться на основе флажка.
Когда я установил флажок, «Точки» будут автоматически заполняться в text3, а «100» будет автоматически заполняться в text4.Теперь всего text7 будет отображаться 130. Значения text5 и text6 отображают «0».Если я напишу что-нибудь, скажем, «10» в text5 и «20» в text6, то итоговый текст7 покажет 160. Если снять флажок, значения text3 и text4 будут удалены, а итоговое значение будет изменено соответственно. Я неУмеет знать, как автоматически заполнить text3 и text4 после установки флажка, есть идеи?
index.jsp
$(document).ready(function() {
$("#combo1").change(function() {
$.getJSON(
'combo1.jsp',
{ combo1Val : $(this).val() },
function(data) {
var a = data.valueoffirsttextbox; //Got 10 from db
var b = data.valueofsecondtextbox; //Got 20 from db
var total = parseInt(a) + parseInt(b);
$("#combo2").val(data.name);
$("#text1").val(a)
$("#text2").val(b)
$("#text7").val(total); // here i am showing total 30 in text7
}
);
// when checkbox is unchecked text4 is not present
$("#text1, #text2, #text5, #text6").keyup(function() {// if any editing occurs
in these values then total will be changed accordingly
var a = $("#text1").val();
var b = $("#text2").val();
var c = $("#text5").val();
var d = $("#text6").val();
var total = parseInt(a) + parseInt(b) + parseInt(c) + parseInt(d);
$("#text7").val(total);// shows total with out text4's value
// when checkbox is checked then text4's value is added
$("#text1, #text2, #text4, #text5, #text6").keyup(function() {// if any editing
occurs in these values then total will be changed accordingly
var a = $("#text1").val();
var b = $("#text2").val();
var c = $("#text5").val();
var d = $("#text6").val();
//here text4 is added
var e = $("#text4").val();
var total = parseInt(a) + parseInt(b) + parseInt(c) + parseInt(d) + parseInt(e) ;
$("#text7").val(total);// show total with text4's value
});
});
});
<body>
<input type="checkbox" id=check"/>
<input type="text" id="text1"/>
<input type="text" id="text2"/>
<input type="text" id="text3"/>// how can i autofill "POINTS" in this
textbox after checking the checkbox?
<input type="text" id="text4" value="0"/>//how can i autofill "100" in this textbox
after checking the checkbox?
<input type="text" id="text5" value="0"/>
<input type="text" id="text6" value="0"/>
<input type="text" id="text7" value="0"/>// shows total of all values of above
textboxes except text3
</body>