I can loop through records with
C#
$("#btnVerTest").on("click", function () {
for (let i = 1; i <= 3; i++) {
if ($("#txtCor" + i).text() == "DA") {
$("#inputRasCor").val($("#txtRas" + i).text());
$("#inputCor").val($("#txtCor" + i).text());
}
};
})where txtCor has id from 1 to 3.
How can I loop through records if all id's have letters instead of numbers, A, B and C? txtCorA, txtCorB, txtCorC and so on


Amit MohantyRank #112 · 20K reputationPosted Aug 19, 2023, 5:03 AM EDT
If your IDs have letters instead of numbers (e.g., txtCorA, txtCorB, txtCorC), you can use an array of letters to loop through them.
$("#btnVerTest").on("click", function () { const letters = ['A', 'B', 'C']; // Add more letters if needed for (const letter of letters) { const txtCorId = "#txtCor" + letter; if ($(txtCorId).text() === "DA") { $("#inputRasCor").val($("#txtRas" + letter).text()); $("#inputCor").val($(txtCorId).text()); } } });Marius VasileRank #785 · 2.9K reputationPosted Aug 19, 2023, 5:05 AM EDT
So simple, thank you Amit
Sam HobbsRank #107 · 20.5K reputationPosted Aug 19, 2023, 10:09 PM EDT
I am sorry that I do not have the exact code to solve your problem but it is possible to convert a letter to a number and a number to a letter as in the following.
let out = ""; for (let i = 'a'.charCodeAt(0); i <= 'c'.charCodeAt(0); i++) { out += String.fromCharCode(i) + " "; } message.innerHTML = out;In the C language and most languages like C, it is very easy to convert a letter to a number and a number to a letter because in C and C++ they are the same thing. JavaScript makes it too complicated.
Cr BhargaviRank #420 · 5.9K reputationPosted Aug 21, 2023, 12:46 AM EDT
Hi, Please try like below
$("#btnVerTest").on("click", function () { const letters = ['A', 'B', 'C']; // Array of letters for (let i = 0; i < letters.length; i++) { const id = "txtCor" + letters[i]; if ($("#" + id).text() == "DA") { $("#inputRasCor").val($("#txtRas" + letters[i]).text()); $("#inputCor").val($("#" + id).text()); } } });