How do I cancel a form submission?

ganeshbala
Kilo Contributor

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);

  }

}

   

}

8 REPLIES 8

vinothkumar
Tera Guru

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().


Thank you so much Vinoth.


Alikutty A
Tera Sage

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


SR2
Tera Contributor

it is not allowing to submit the, even when we enter the correct answer.