首页 > 解决方案 > datalist selected value is "null" in the sheet

问题描述

I have a datalist problem : I have too much values in my datalist to use a simple select. I changed my html to use a datalist instead. The problem is that the selected value is "null" when i want to set it in the sheet. The values are like : "PDCTLEA1-N00C06" in "mesSwitchs" list.

<script>              
              function validerAd()  
              {
            
                let idPort1a = document.getElementById("idPort1a").value; 
                
                google.script.run.nouvAdresse(idPort1a);
              }
<form>
      <p8>
          <label for="idPort1a" id="labelPort1a">Choisissez un switch :</label>
          <input list="idPort1a" name="idPort1a" id="idPort1aListe">

          <datalist id="idPort1a">
            <br/>
            <? for (var i = 0; i < mesSwitchs.length; i++) { ?>
            <option value="<?= mesSwitchs[i][0] ?>" ><?= mesSwitchs[i][0] ?></option>
            <? } ?>
          </datalist>
      </p8>
function nouvAdresse(idPort1a)
{
 AdressesIP.getRange(2,2).setValue(idPort1a);
}

In the sheet, it will set "null" instead of the selected value. Do you know why ?

标签: javascripthtmlgoogle-apps-scriptgoogle-sheets

解决方案


Only thing I can think is a typo. You're using idPort1a everywhere.

But you're trying to paste idPort1 (without a) in your function.

Probably your function should look like this:

function nouvAdresse(idPort1a)
{
 AdressesIP.getRange(2,2).setValue(idPort1a); // <-- here
}

Just a guess.


推荐阅读