How to detach jQuery event handler from a object?

Few days back I was working on a page in which jQuery validation was atatched to the Form object. I had a unique requirement in that file. I had 2 button. When user press button 1 then the form should not validate and if user click on button 2 then form should validate. the problem was with me that if user click first on button 2 then validation event bind to the form and button 1 requirement do not work. after reading the jQuery thread, I found a solution which I explained below as example.

<html>

<head>

<script>

function save_form(js_clicked)

{

if(js_clicked == “WIP”)

{

jQuery(function( $ )

{

$(‘#contactForm’).unbind();

});

}

else

{

jQuery(function( $ )

{

$(“#contactForm”).validate();

});

}

}

</script>

</head>

<body>

<form method=”post” action=”text.php” name=”contactForm”>

<input id=”box1″ title=”box1 value is required” class=”required” />

<input id=”box2″ title=”box2 value is required” class=”required” />

<input value=”Save Entered Data” />

<input type=”submit” value=”Send Form” />

</form>

</body>

</html>

Tags: , ,

Leave a Reply - Comment related to topic will only be accepted