code.gs:
function globalVariables(){
var varArray = {
spreadsheetId : '1MQQK6P-4DccBogN7at5x66m7dyaDSx4FdeiSz9XhxoY', //** CHANGE !!!
dataRage : 'Data!A2:K', //** CHANGE !!!
dataRage2 : 'Data2!A2:K', //** CHANGE !!!
idRange : 'Data!A2:A', //** CHANGE !!!
idRange2 : 'Data2!A2:A', //** CHANGE !!!
lastCol : 'K', //** CHANGE !!!
insertRange : 'Data!A1:K1', //** CHANGE !!!
insertRange2 : 'Data2!A1:K1', //** CHANGE !!!
sheetID : '0' //** CHANGE !!! Ref:https://developers.google.com/sheets/api/guides/concepts#sheet_id
};
return varArray;
}
function getContactList(range){
var list = readData(globalVariables().spreadsheetId,range);
return list;
}
Javascript.html:
function checkdata() {
google.script.run.withSuccessHandler(blurFunction).getContactList("Data!D1:D195");
}
function blurFunction(values) {
//Ref: stackoverflow.com/a/53771955/2391
for (var i = 0; i < values.length; i++) {
for(var j=0; j<values[i].length; j++){
result = values[i][j];
console.log(result);
var list = document.getElementById('contact').value;
if (list == result){
document.getElementById("contact").style.background = "blue";
}
else {
document.getElementById("contact").style.background = "yellow"
}
}
}
}
Form.html:
```html
div class="form-group col-md-6">
<label for="contact">Contact</label>
<input type="tel" class="form-control" id="contact" name="contact" placeholder="contact" onblur="blurFunction()">
</div>
</div>
It gives me error:
userCodeAppPanel:230 Uncaught TypeError: Cannot read properties of undefined (reading 'length')
at blurFunction (userCodeAppPanel:230:32)
at HTMLInputElement.onblur (userCodeAppPanel:1:14867)
blurFunction @ userCodeAppPanel:230
onblur @ userCodeAppPanel:1
How to highlight form.html Contact input when there's a duplicate data from Spreadsheet?