Onsubmit client script

surya123
Mega Guru

HiAll

I am writing a onsubit client script where i want to check if the fields are populated with correct values or not before submitting the form.

Reason - we have onchange client script but we saw that sometimes the value gets corrupted or beomes undfined on submit and it creates an issue..

function onSubmit() {

var user = g_form.getValue('user');   //variable name. I am fetching the values on user table to populate 2 fields on catalog item.

var scriptInclude = new GlideAjax("UserData");

scriptInclude.addParam('sysparm_name','data');

scriptInclude.addParam('sysparm_id',user);

scriptInclude.getXMLWait(retrieveValues);

    //Type appropriate comment here, and begin script below

   

}

function retrieveValues(response){

var answer = response.responseXML.documentElement.getAttribute("answer");

var Value = answer.split(',');

var m,n,s;

m =g_form.getValue('userd');

n =g_form.getValue('manager');

s =g_form.getValue('department');

alert(m +Value[0].toString());

alert(Value[1].toString());

alert(Value[2].toString());

if(m == Value[0].toString() && n ==Value[1].toString() && s==Value[2].toString())

{

return true;

}

else{

alert("Please re-enter the User again");

return false;

}

}

This submits and i dnt see any alert. how can i match what was entered on form and the user value fetched.

1 ACCEPTED SOLUTION

bernyalvarado
Mega Sage

Hi Surya,



That looks like asynchronous call instead of a synchronous one, which is what you need at a onSubmit script.



getXMLWait shouldn't be taking a callback method as a parameter



Thanks,


Berny


View solution in original post

7 REPLIES 7

bernyalvarado
Mega Sage

Hi Surya,



That looks like asynchronous call instead of a synchronous one, which is what you need at a onSubmit script.



getXMLWait shouldn't be taking a callback method as a parameter



Thanks,


Berny


bernyalvarado
Mega Sage

You need to have your return (false) and any alert within the scope of the code that gets executed.



Take a look to some examples of getXMLWait and that should help



Thanks,


Berny


bernyalvarado
Mega Sage

For instance:



Examples of synchronous GlideAjax



Thanks,


Berny


Thanks I was scratching my head since yesterday.