Monday, 26 August 2013

Binding event to programmatical form submission

Binding event to programmatical form submission

There is a form and a button.
<a href="javascript:myFunc();">submit</a>
<script>
function myFunc()
{
//some actions here
$('formSelector').submit();
}
</script>
Now I want to bind another function to submit event of the form without
modifying the first part:
<script>
$('formSelector').on('submit', function(){
alert(123);
});
</script>
The above function is not executed. The form is submitted by myFunc()
Is there a way to alert(123) before form submit?

No comments:

Post a Comment