I am trying to achieve VLOOKUP within HTML using Google Apps Script and JavaScript.
We have Google site in which a HTML form is designed with Google Apps Script. User will have to enter their ID value in ID field and their name will be auto populated in the name field.
Only one Google spreadsheet file is used. One tab is to receive the user's entry another tab got the list of ID and name of the users.
Following are my tries:
- Google apps script:
function FindName(uin) { var data=Udata.getRange('A2:B').getValues(); var valA=uin; for(nn=0;nn<data.length;++nn){ if (data[nn][0]==valA){break} ; }Logger.log(data[nn][1]);return (data[nn][1]);} - JavaScript (Updated): With this update I am getting undefined value in the name field:
function fetchName(){ var userId = document.getElementById("uin").value; document.getElementById("Name").innerHTML = google.script.run.FindName(userId); } - HTML form code:
<div class="mb-1"><label for="uin" class="form-label">Enter uin:</label><input type="text" id="uin" name="uin" class="form-control form-control-sm" onkeyup="fetchName()" required> </div><div class="mb-1"><label for="Name" class="form-label"> Name:</label> <input type="text" id="Name1" name="Name1" class="form-control form-control-sm" required> <p>Welcome <span id="Name"></span></p></div>
But onkeyup the name never gets populated.
When I feed in the ID value in Google script manually and check with debugging the name appears in the log, but in HTML form it doesn't work.