0

I am trying to figure out server/client data type matching. In the html with javascript, form itself is supposed to be sent to google code.gs.

<body>
<form id='form1'>
    <div>
     ....buttons and input texts...
    </div>

-- here the last button's onclick I call lSubmit(this.parentNode)

<button type="button" 
onclick="lSubmit(this.parentNode)" 
id=btn>click</button>

</form>
<script>
var x = $("#output");

function lSubmit(formObj) {
    x.html('Wait until verified.');
    google.script.run
      .withSuccessHandler(onSuccess)
      .withFailureHandler(onFailure1)
      .chkForm(formObj);
}
</script>

As I was not well aware of parentNode, it took whole day for me to figure out what my mistake was. Because I used 'div' after form, lSubmit was taking div.

My question is,

code.gs

function chkForm(formObj) {
  Logger.log("chkForm in Code.js called. id: %s",formObj.uname);
  return 'You entered id' + formObj.uname + ' to login...'; 
}

As I was sending div, but chkForm wants to receive form, isn't there supposed to be some error code returned? But in the server log doesn't say 'undefined' or object type or formObj.uname doesn't exist kind of sorts. Nor end result in javascript withSuccessHandler, withFailureHandler. Actually, lSubmit wasn't called I think. Because I didn't see the comment Wait until verified.

Just like some typo, this time was too difficult what went wrong.

Last question I asked was also ended up wrong in data handling where server returns date but javascript can't handle. But in that case, withFailureHandler worked. So it was figured out quickly. However, now, what should I add to where so that I can catch that there is an error in data type mismatch between server and client? Like in this case, that client is sending wrong data?

Is it javascript refusing to run as it saw mismatching?

  • A new user that has detailed and formatted answers. Wow! Glad to see new people like you joining our big family. Welcome! :-) – Jorge Fuentes González Apr 21 '18 at 14:19
  • @Jorge Fuentes González Thanks. Trying to learn and helpful to the forum too. Because all those ppl's q&a I got benefitted from was well formated&detailed. –  Apr 21 '18 at 14:21
  • The first thing to try is to see if `lSubmit` was called, yep. By the way, avoid inline javascript as much as you can. If your button has a unique ID, try to attach the "click" event to the button using javascript, like this: `document.getElementById("BUTTON_ID").addEventListener("click", FUNCTION)` – Jorge Fuentes González Apr 21 '18 at 14:29
  • And the function will receive an event, where you can get the `currentTarget` and access his `parentNode`, like this: `function(event){ lSubmit(event.currentTarget.parentNode) }` – Jorge Fuentes González Apr 21 '18 at 14:30
  • `currentTarget` of an event is the node where the event handler is attached, the button in this case. Do not confuse with `target`. – Jorge Fuentes González Apr 21 '18 at 14:32
  • @Jorge Fuentes González I gotta learn so many things. addListener is a new thing to me and at the moment, I am just copying and pasting to my project. –  Apr 21 '18 at 15:44
  • Then is it a good practice to use this addEventListener way to handle functions in javascript? –  Apr 21 '18 at 15:45

0 Answers0