When Dialog is loading, data isn't passed properly

When Dialog is loading, data isn't passed properly

The page I'm working on right now is a cart checkout page, in which I want to make sure all the cart quantities have been saved before moving on to complete checkout. I have it set up so that if any quantities have been changed without also being saved, a dialog box pops up allowing the user to either save the changes or continue without saving. To save the changes, I have to loop through the changed quantities and send each item individually to a pre-existing page that updates the database. Now, everything is working perfectly fine except for when the theme images haven't finished loading before hitting the save button. Is this something a simple wait function can fix, or is there some way to detect when the images have finished loading?