Can you help me with a JavaScript code to validate 7 textboxes as Required fields when a button named Update is clicked? I am new to JS and the code I have tried so far is not working properly.
function fnCheck(val) {
var v = val.id.split('_')[1];
var merter = document.getElementById('GridSubMeter_' + v + '_txtMeterIdn').value.trim();
var Billper = document.getElementById('GridSubMeter_' + v + '_txBillPer').value.trim()
var Endkwh = document.getElementById('GridSubMeter_' + v + '_txEndKwh').value.trim();
var startkwh = document.getElementById('GridSubMeter_' + v + '_txStartKwh').value.trim();
var ReadEndDate = document.getElementById('GridSubMeter_' + v + '_txReadEndDate').value.trim();
var ReadStartDate = document.getElementById('GridSubMeter_' + v + '_txReadStartDate').value.trim();
var CTFACT = document.getElementById('GridSubMeter_' + v + '_txCTFact').value.trim();
if (merter === '' || Billper === '' || Endkwh === '' || startkwh === '' || ReadEndDate === '' || ReadStartDate === '' || CTFACT === '') {
alert("Please fill in all required fields");
return false;
} else {
return true;
}
}
<asp:Button ID="btn_Update" Style="background-color: #B2DE94; width: 40px" CausesValidation="false" runat="server" OnClientClick="fnCheck(this);" Text="Update" CommandName="Update" />