How do I cancel a form submission?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2017 02:48 AM
I would like to cancel the form submission in case the "if" statement below is true. how can I acheive that?? I added "return false" inside the if statement but its not working. kindly do help me out..
function onSubmit() {
//Type appropriate comment here, and begin script below
var t = g_form.getValue('u_date');
var a = new GlideAjax('testscript');
a.addParam('sysparm_name','myfunction');
a.addParam('sysusername', 'bala');
a.getXML(myback);
function myback(res)
{
var answer= res.responseXML.documentElement.getAttribute("answer");
if(t!=answer)
{
alert("current date is" + answer);
}
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2017 03:09 AM
Hi Bala,
Using a callback in an onSubmit function does not really make much sense. You definitely want to use a callback with onChange scripts because you do not want to lock the screen on the user while they are adding information. When they click on the submit button, the user is done, or at least they think they are, until you evaluate the dates.
I would stick with the getXMLwait().
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2017 09:30 PM
Thank you so much Vinoth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2017 03:09 AM
Hi,
You should be adding return false in the main onSubmit function.
function onSubmit() {
return false;
}
It wont work if you add a return false in your callback or any sub functions. You should be returning back a false flag to the main onSubmit function and then call return false from it.
Thanks
Please Hit like, Helpful or Correct depending on the impact of the response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2021 02:29 AM
it is not allowing to submit the, even when we enter the correct answer.