How to call a function from an OnLoad Client Script from an Onsubmit client script?

Community Alums
Not applicable

I need to be able to update the value of a field in an OnLoad Client Script. I am calling the function that updates the field from an OnSubmit Client Script but I am not sure that I am calling the function correctly. I leave the code that I am using:

Catalog Client Script OnSubmit:

function onSubmit() {

    var totalCost = 10;
    updateGrandTotal(totalCost);
}

 Catalog Client Script OnLoad:

function updateGrandTotal(totalCost) {


    g_form.setValue('grand_total', totalCost);


}

function onLoad() {

	

}
5 REPLIES 5

Kristen Ankeny
Kilo Sage

You would not call another client script, you would put the code you need directly in the onSubmit client script.

Community Alums
Not applicable

Hello Kristen, thank you for your answer. Yes, I know I can do that but in this case for X reason I need to call a OnLoad Client script, I am not allowed to put the code in the same client script. 

Is this a company policy? If so, then what is the business rule you are trying to build these two client scripts for? There might be another way to accomplish this ask.

Nitin22
Tera Expert

Hi Rico , I am not sure what your use case here is , but the approach is incorrect , if you can tell your exact need i can suggest you alternate solution but you can't call a function this way.