Waza_Be
Waza_Be

Reputation: 39558

Google Sheet webapp: Display a button programmatically

I am trying to display a button under certain condition on my HTML output

I succesfully wrote the code like this:

      <?
        var HTMLToDisplay = "";
        if (data[i][5] == 0) {
          HTMLToDisplay = ""
        } else {
          HTMLToDisplay = '<input type="button" value="Réserver" onclick="openForm(' + "'" + new Date(data[i][4]).toLocaleDateString('fr-BE', options) + "'" + ",'" + data[i][3] + "'," + data[i][0] + ')" />'
        } 
      ?>
                    
      <?= HTMLToDisplay ?> 

But unfortunately, the HTML code appears in plain text rather than in the code

enter image description here

In fact the script automatically added some unwanted double quotes

enter image description here

Any idea how I can display my button just by code, without doing complex stuff?

Thanks a lot

Upvotes: 0

Views: 65

Answers (1)

Tanaike
Tanaike

Reputation: 201408

In your script, please modify as follows and test it again.

From:

<?= HTMLToDisplay ?>

To:

<?!= HTMLToDisplay ?>

By this, if the value of HTMLToDisplay is the valid HTML tag, the value of HTMLToDisplay put as the raw string. When it is loaded by the browser, it is shown as a button. If no button is shown, please check the value of HTMLToDisplay again.

Reference:

Upvotes: 1

Related Questions