[jQuery] Comparing 2 field values in custom method

[jQuery] Comparing 2 field values in custom method


I've been hacking at this for a couple days now and it's driving me
batty since there isn't a whole lot of info or many examples of use
with params, splits on params, and then comparing fields other than
the equalTo which essentially does below but this isn't working for my
custom validator. I know I'm close but just can't figure out what I'm
missing or doing wrong here in my syntax. I've tried different
variations such as using the split function and then assigning it to a
var and that didn't work either.
The check for the checkbox to see if it's checked is working, it is
just the way I'm trying to check for equality which is not and so
whenever I check the box after an initial submit on the form, the
checking of the box keeps bringing up my error message so I know my
logic isn't right inside my second if statement below.
I'm simply trying to create my own validator which passes in 2 fields
and compares them to see if they are equal:
<script type='text/javascript'>
$(document).ready(function()
{
$("#BillingForm").validate
({
rules: {
compareAddressesCheckbox: {compare:
["#txtfield1","#txtfield2"]}
}
});
});
</script>
// compare 2 fields if checkbox is checked
jQuery.validator.addMethod("compare", function(value, element,
params) {
     // is checkbox checked?
     if (value == true)
     {
if (jQuery(params[0]).val() ==
jQuery(tparams[1]).val())
{
return jQuery(tmp[0]).val() ==
jQuery(tmp[1]).val();
}
}
else
{
return this.optional(element);
}
}, "Fields do not match");