I am using a Telerik Datetime
control. On onBlur
event of input box I am checking if the date is valid/in-valid, based upon that I am enabling or disabling the submit button (anchor tag actually).
var embedUrl = null;
function onBlur(sender) {
var constants = {
classDisabled: 'button-disabled',
emptyHref: "javascript:void(0)"
};
if (sender) {
var jqueryButton = window.jQuery('.button-submit');
if (!embedUrl) {
embedUrl = jqueryButton.href;
}
// Check if the string is valid date.
// As it's being triggerd from Telerik so we use _invalid
if (sender._invalid) {
// Date is in-valid, add the class disabled if it does not exists.
if (!jqueryButton.hasClass(constants.classDisabled)) {
jqueryButton.attr('href', constants.emptyHref);
jqueryButton.addClass(constants.classDisabled);
}
} else {
// Date is valid, remove the class disabled if already exists.
if (jqueryButton.hasClass(constants.classDisabled)) {
jqueryButton.attr('href', embedUrl);
jqueryButton.removeClass(constants.classDisabled);
}
}
}
}
I have an anchor tag which has some href
which I need to persist.
I want to know how I can write this code a little cleaner.