0

Hi I'm trying to insert a value from my google sheet next to my materialize checkbox if the checkbox is true i need it to return the value from my google sheet if the checkbox is false it would leave it blank I've tried all kinds of ways but cant get it to work.

HTML

   <form action="#">
     <p>
      <label>
        <input type="checkbox" id ="NewJobSW" class="filled-in" >
        <span for="NewJobSW">New Job</span>
      </label>
    </p>

  </form>
   <div>
    <h5><span  id='getNJ'> </span></h5>
   </div>

JS code

     <script>
          <?
          var sheet   = SpreadsheetApp.openById("1QMgcxD4ujIE95a3GbA5hVU8lXrackjTwdHECqY0ks").getSheetByName("HelpSheet");
          var data = sheet.getRange("D2").getValue();
          ?>
          google.script.run.withSuccessHandler(getNJ).getNJ();

          function getNewJob(getNJ){

              var triger= document.getElementById("NewJobSW").value;  
                   if(triger = true){                 
                       document.getElementById('getNJ').innerHTML = getNJ
                    }else if(triger = false){
                         document.getElementById('getNJ').innerHTML = ""

                    }
      </script>

Thanks

Yvan L
  • 233
  • 3
  • 12
  • 2
    `` and `?>` isn't valid JavaScript. Are you using a server side scripting language like PHP? – David784 Jan 31 '20 at 20:48
  • 2
    You may want to use comparison operators (`==`) instead of assignment operators (`=`); see [== vs =](https://stackoverflow.com/questions/11871616/in-javascript-vs). – showdev Jan 31 '20 at 20:50
  • You are using Apps Script methods (e.g. `openById`) in client-side. This cannot work. Are you trying to publish an Apps Script web app? Can you provide the rest of the code you're using, if any? – Iamblichus Feb 03 '20 at 09:22

1 Answers1

0

A checkbox can only be checked in this way...

 if(NewJobSW.checked){getNJ.innerHTML='123';} else {getNJ.innerHTML='0';}

NB: I used "123" as an example but you'll have to assign the value properly from your spread sheet.