prevent form auto-submit on keypress enter

21 views
Skip to first unread message

tinker shukla

unread,
Jan 28, 2020, 12:26:09 AM1/28/20
to Google Apps Script Community
hi guys
the problem is 
when the input field in active i.e. while the cursor is active in the input box , on pressing enter key the form gets submitted to some unknown address which is not defined in the appscript or javascript code. 

The form is hosted in appscript using the htmlservice function

Andrew Roberts

unread,
Jan 28, 2020, 2:25:54 AM1/28/20
to google-apps-sc...@googlegroups.com
Have you disabled the default action on form submit?
--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-community+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/3919b6f2-a598-4791-b011-da2f0112c9c5%40googlegroups.com.

--Hyde

unread,
Jan 28, 2020, 8:55:07 AM1/28/20
to Google Apps Script Community
See index.html at https://developers.google.com/apps-script/guides/html/communication#forms. That sample uses form.addEventListener('submit', function(event) { event.preventDefault(); }); and a separate function to handle form submit with <form id="myForm" onsubmit="handleFormSubmit(this)">.

Cheers --Hyde

Alan Wells

unread,
Jan 28, 2020, 9:02:26 AM1/28/20
to Google Apps Script Community
An HTML form has a default / built-in behavior of making a HTTPS GET request when a button is clicked inside of the <form> tags, which then refreshes the browser tab. There are quite a few ways to handle submitting an HTML form.  To prevent the default action:
  • Javascript - prevent default
  • Move any buttons outside of the <form> tags - Then get the form answers

There are a couple of ways that you can get the answers out of the HTML <form> tag, without using the default form submission action.
  • Get the html <form> tag and submit the form object
  • Get values individually out of every element

Reply all
Reply to author
Forward
0 new messages