I am porting an application from struts2 to spring 3 mvc.
So far the forms are fine but now I have hit a problem with the javascript.
I have a button that launches a js script function to reset the form. I can see the function is being executed via use of an alert but the form just does not reset back to the original state when the script fires.
I have a similar script function which resets a hidden variable but when changing the value from the original '0', to '1', it actually changes the value to '1,0'.
Also there is a script function which removes the onbeforeunload action but this also does not work.
The same form with the same js under struts2 works fine, with all the script functions doing exactly as they are supposed to do.
Is there anything special I have to do to get javascript to work properly in jsp under spring/mvc?
Here are the javascript functions
Code:<script language="javascript" type="text/javascript"> function submitHandler(buttonPressed) { if ( buttonPressed == document.getElementById('acceptFullAllocation').id || buttonPressed == document.getElementById('unassignFullAllocation').id || buttonPressed == document.getElementById('saveAllocations').id ) // remove window.beforeunload so these operations can continue without warnings { window.onbeforeunload = null; } } function changeHandler(modifiedObject) { // mark the form as modified document.getElementById('formChanged').value = '1'; // determine which form element was modified var tagObject = 'status_' + modifiedObject; // let the form action target know which form element has been modified document.getElementById(tagObject).value = '1'; // add onbeforeunload event handler to advise user pf pending changes window.onbeforeunload = function() { return('${sessionObject.getPropContent("Pager.changes.confirm")}'); } } function resetForm() { if (confirm('${sessionObject.getPropContent("Pager.changes.reset")}')) // reset the form and all navigation locks { // mark the form as unmodified document.getElementById('formChanged').value = '1'; // remove the onbeforeunload handler window.onbeforeunload = null; // reset the form document.getElementById('seatsForm').reset(); // iterate the form elements $(':input', document.getElementById('seatsForm')).each(function() { if (this.name.substring(0, 7) == 'status_') // this is a modifier flag, so reset it { this.value = '0'; } }); } // remove window.beforeunload // return false here to cancel the action return(false); } </script>


Reply With Quote