I'm trying to make a form that when you press the button it will validate, if the validation is successful if will call a function which will do a few things (saving form data to local storage etc).
The problem is I can't get the submitHandler to fire the function. Here is the jsFiddle I've been working on.
http://jsfiddle.net/JamesKrawczyk/xdo9nn48/
And the code.
<script>
function fireifworked()
{
$('.testIfWorking').html('IT WORKED');
}
$(document).ready(function() {
$("#form1").validate({
rules: {
field1: "required"
},
messages: {
field1: "Please specify your name"
},
submitHandler: function(form) {
fireifworked();
}
})
$('#btn').click(function() {
$("#form1").valid();
});
});
</script>
<form id="form1" name="form1">
Field 1: <input name="field1" type="text" />
</form>
<div>
<input id="btn" type="button" value="Validate"/>
</div>
<div class="testIfWorking">
CHANGE THIS IS WORKING
</div>