[jQuery] Unbind not unbinding
I've got the following:
var existingCodes = new Array('<?php echo implode("','",
$existingCodes); ?>');
var form = document.newSpecificLeadSourceForm;
$('#suggestCode').click(function() {
$(this).css('display', 'none');
$(form.source).bind('keyup', function() {
var code = $(this).attr('value').replace(/[^A-Z0-9\-]/ig, '');
if (existingCodes.indexOf(code) == -1)
$(form.code).attr('value', code);
}).keyup();
}).click();
$(form.code).focus(function() {
$(form.source).unbind('keyup');
$('#suggestCode').css('display', 'inline');
});
On the page, I have a form with two text fields (source, code) and a
link (suggestCode). The script will create in the "code" field, a
stripped down version of the text in the "source" field on every
keypress. When the "code" field is focuses it [should] deactivate
this behavior and allow for the user to create their own code. (It
also displays the suggestCode link to reactivate the behavior.)
My problem is the unbind is not working. Everything else works fine,
but after entering in text into the "code" field (which should
deactivate auto code suggestion), and typing in the "source" field
again, the suggestion is still turned on.
I could work around the issue with a "suggestionOn" boolean, but that
would be admitting defeat. Why isn't unbind behaving?