0

Previously, the row variable was manually entered with:

row <input type="text"  name="row" />

How is that parameter, which is now marked hidden, made mutable, as when the type was input as above?

<!DOCTYPE html>

<html>

<head>
  <base target="_top">
</head>

<body>
  <h1>iterator</h1>
  <form action="<?= url ?>" method="GET">
    note <input type="text"  name="update" />
    <br>
    <input type="submit" name="Submit" /><br> <br> <br>
    <input type="hidden" name="row" value="3487">
    <span><?= params ?></span> <br> <br> <br>
    <span><?= update ?></span> <br> <br>
    <span><?= row  ?></span> <br> <br> <br> <br>
    <span><?= values ?></span> <br>
  </form>

</body>

</html>

The notion is to iterate through the row's of a spreadsheet, and so the row should increment each time it's used (or the submit button is clicked). To increment the value it must be mutable and then sent back as a parameter to Code.js where it's used to query the Google Sheet.

Would this be accomplished with a <script> tag, perhaps?

1 Answers1

2

You might use JavaScript and the DOM API on the client-side, but first, you might take advantage of the id attribute

<input id="something" type="hidden" name="row" value="3487">

Then in use JavaScript / DOM API to change the value as follow:

document.querySelector('#something').value = "3488";

You should add the above line in appropriate place in your HTML. It might be on onclick attribute of a button, in a <script>, as part of function called someway, i.e. by clicking a button. To call the function you might use button onclick attribute to set the function to be called or use HtmlElement.addEventListener to set the function to be called when the element event occurs.

Another option is to use a scriptlet as you have done in the <span>'s, but instead of adding it as the tag content, put the scriptlet instead of the default value:

<input  type="hidden" name="row" value="<?!= valueFromServerSide ?>">

Please note the use of !, this is to indicate that should not use contextual escaping, in other words, to add the value assigned to the variable as is.

Related

Rubén
  • 34,714
  • 9
  • 70
  • 166
  • where you use the `#something` syntax, would that be in the `HTML` document? – Nicholas Saunders Oct 11 '22 at 06:06
  • 1
    Yes. The DOM API is available on the client-side, not in the server side. – Rubén Oct 11 '22 at 06:07
  • Added another option – Rubén Oct 11 '22 at 06:11
  • I'm intrigued by the scriptlet you mentioned. This is a proprietary feature from Google Apps Script? Referencing: https://codewithcurt.com/how-to-link-between-google-web-app-pages/ although I haven't yet had time to digest the info. – Nicholas Saunders Oct 12 '22 at 09:19
  • I can't tell for sure, but I don't think. Java uses `<% %>`, PHP use ``/ ` ?>` and other languages might use something similar to embed server-side scripting in html files – Rubén Oct 12 '22 at 09:33