I am having a confirmation box with a input field requesting a date. When the confirmation box appears, the input box is in focus. How do I unfocus it? I need to drop down a calendar when I click on the input field. Here is my relevant code:
$(".confirmLink").click(function(e) {
e.preventDefault();
var targetUrl = $(this).attr("href");
document.getElementById('dialog').focus();
$("#dialog").dialog({
buttons : {
"OK" : function() {
window.location.href = targetUrl+"/"+"deletedDate"+"/"+document.getElementById('deletedDate').value;
},
"Cancel" : function() {
$(this).dialog("close");
}
}
});
$("#dialog").dialog("open");
});
function datepicker(){
$( "#deletedDate" ).datepicker(
{
dateFormat: 'yy-mm-dd',
changeMonth: true,
changeYear: true,
showAnim: "slideDown"
});
}
The blur() method removes focus from an element.
The focusout() method in jQuery is used to remove the focus from the selected element. Now we will use focusout() method to validate the input field while focussing out. This method checks whether the input field is empty or not. Also, use some CSS property to display input field validation.
jQuery blur() MethodThe blur event occurs when an element loses focus. The blur() method triggers the blur event, or attaches a function to run when a blur event occurs. Tip: This method is often used together with the focus() method.
This should do the trick:
.blur();
(as was pointed out - this is sufficient)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With