How to call a function from an OnLoad Client Script from an Onsubmit client script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2023 11:03 AM
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() {
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2023 03:53 AM
Hi @Community Alums ,
You can use the g_scratchpad variable to pass data between the two scripts.
First, in your OnLoad Client Script, define the updateGrandTotal function and store it in the g_scratchpad variable:
function updateGrandTotal(totalCost) {
g_form.setValue('grand_total', totalCost);
}
g_scratchpad.updateGrandTotal = updateGrandTotal;
Then, in your OnSubmit Client Script, retrieve the updateGrandTotal function from the g_scratchpad variable and call it with the necessary parameter:
function onSubmit() {
var totalCost = 10;
g_scratchpad.updateGrandTotal(totalCost);
}
This will allow you to update the value of the 'grand_total' field from the OnSubmit Client Script by calling the function defined in the OnLoad Client Script.
If my response was helpful in resolving the issue, please consider accepting it as a solution by clicking on the ✅Accept solution button and giving it a thumbs up 👍. This will benefit others who may have a similar question in the future.
Thank you!
Ratnakar