0

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?

1
  • You are not passing any values in onblur="blurFunction()" Commented Jan 1, 2023 at 11:31

1 Answer 1

0

Function blurFunction is the call back from the google.script.run.withSuccessHandler.

Change

<input type="tel" class="form-control" id="contact" name="contact" placeholder="contact"  onblur="blurFunction()">

To

<input type="tel" class="form-control" id="contact" name="contact" placeholder="contact"  onblur="checkData()">

And

if (list == result){ 

To

if( Number(list) == result ) {
Sign up to request clarification or add additional context in comments.

4 Comments

tq! it works now! but still didnt highlighted the duplicate entry
i've edited my code: 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"; } } }}
my console log did shows the array value, but when i keyed in say "5454" it still shows Yellow Net state changed from BUSY to IDLE VM145:238 contact VM145:238 5454 VM145:238 1 VM145:238 ererer VM145:238 45 VM145:238 56 VM145:238 1234 VM145:238 898 VM145:238 09 VM145:238 34 VM145:238 scv
it works!! thanks so muchh! and I also did remove the else statement tq again Sir!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.