Home > Mobile >  How to assign a value obtained from spreadsheet to the value attribute of <input>?
How to assign a value obtained from spreadsheet to the value attribute of <input>?

Time:01-26

I'm working with an HTML template by Google Apps Script in Google Sheets. I'm having a hard time figuring out how to set the value attribute of with a variable assigned from a value taken in spreadsheet.

My goal is to create an HTML template, in which the inputs already appear with the defined values, but editable.

Can someone help me with this?

CodePudding user response:

I usually do it like this:

In the HTML template, I use:

<!DOCTYPE html>
<html>
  <head>
  <Title> Test email </Title>   
  </head>
  <body>
   <h1>Sending emails with values in Sheet </h1>
   <p></p>
   <p>Hello <?= Client_name ?>!</p>
   <p>We are confirming the order: <?= Order_number ?></p>
   <p></p>
   <p>The items requested are: </p> 
   <p><?= Items ?></p>
   <p></p>
   <p> Please confirm the order soon as possible.  </p>
   <p></p>
   <p> Thanks!</p> 
  </body>
</html>

Inside the Apps script code, you need to add the variables

  var vClient_name = 0;
  var vOrder_number = 1;
  var vItems = 2;

In my case, since I was going to use those values to send an email, I link those variables with the brackets like this:

 Emailtemp.Client_name = row [vClient_name];
 Emailtemp.Order_number = row [vOrder_number];
 Emailtemp.Items = row [vItems]
  •  Tags:  
  • Related