In my mvc 3 application, I would like to execute a function when the user tries to submit the form. Within that function I will check a number of fields to determine if the user has provided the necessary data before submission.
How can I hookup a script to be executed when the user tries to submit the form?
(within the custom validate function, I need to check if various checkboxes have been selected and if yes, then additional values are selected from dropdownlists etc.)
You could subscribe to the
.submitevent of the form and after calling the standard client side validation call your custom function:Another possibility is to write custom validation attributes and hook up a custom adapter as shown in this answer and a similar one.