I have a button onclick of which a jquery dialog appears with two input fields which are jquery datepickers. Whenever the dialog appears, the first fields gets focus automatically, hence the datepicker pops up. I have resolved this for now by adding another dummy input field. Is there a better way ?
Sorry if the question is repeated. I tried searching for one already existing but couldn't get one. Please point me to an existing question if present.
Edit:
Okay my code goes as follows. onClick of a button the jdialog appears and there are 2 datepicker input fields inside the div "select_date_dialog".
$("#select_date").click(function(){ $("#select_date_dialog").dialog({ modal: true, dialogClass: 'connect-dialog', height: 100, width: 500 }); });
afaik: can you be a bit more specific how blur will help me ? I tried adding this as suggested.
open: function(event, ui) { $('#custom_from_date').blur(); }
blur happens when there input field loses focus. can i use blur to specify whether that field should get focus or not ?
The blur() method removes focus from an element.
The focusout() method attaches a function to run when a focusout event occurs on the element, or any elements inside it. Unlike the blur() method, the focusout() method also triggers if any child elements lose focus. Tip: This method is often used together with the focusin() method.
To set focus to an HTML form element, the focus() method of JavaScript can be used. To do so, call this method on an object of the element that is to be focused, as shown in the example. Example 1: The focus() method is set to the input tag when user clicks on Focus button.
To check if an input field has focus with JavaScript, we can use the document. activeElement property to get the element in focus. to add an input. to check if the input element is focused.
You could create a handler for the dialog's open
event and blur the field in that:
$("#mydiv").dialog({ open: function(event, ui) { $('#theinput').blur(); } });
I'd need to see more of your code to be any more specific though.
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