0

I would like to get the value from my custom dialog (HTML) to use it as a string parameter to a function.

Dialog.html:

   <form id="subject-form">
    <div class="form-inline">
      <input type="text" id="subject" placeholder="Bookmark name" name="subject" maxlength="16" required >
      <span>.</span>
      <div class="select-dropdown">
        <select id="selector">
          <option value="student">student</option>
          <option value="cs">cs</option>
          <option value="hr">hr</option>
        </select>
      </div>
      <span>.xyz.com</span>
    </div>
    <div class="btn-container" id="dialog-button-bar">
      <button type="submit" class="action" onclick="getLabel()">Add</button>
      <button id="dialog-cancel-button" onclick="google.script.host.close()">Cancel</button>
    </div>
    <!-- <div id="dialog-status"></div> -->
  </form>

DialogJS:

  function getLabel () {
    const subj = document.getElementById('subject').value;
    const subd = document.getElementById('selector').value;

    google.script.run
    .withSuccessHandler()
    .mailIt(subj, subd);

  }
Rubén
  • 34,714
  • 9
  • 70
  • 166
Pablo
  • 145
  • 1
  • 8
  • What is the question? Besides clarifying that, please provide a [mcve] : include the server side code to open and receive the data from the dialog, include the textual error message if you get one. Also add a brief description of your search efforts as is suggested in [ask]. – Rubén Sep 15 '22 at 02:03

1 Answers1

1

The problem is that you are reloading the page every time you press the button.

Change this:

<form id="subject-form">

To this:

<form onsubmit="return false" id="subject-form">

Then the function will work as expected.

Reference:

Emel
  • 2,283
  • 1
  • 7
  • 18