Solved

Jquery datepicker setting focus to textbox

Posted on 2014-01-31
3
2,380 Views
Last Modified: 2014-02-06
Hello Experts,

We use the jquery datepicker throughout our application.  I am trying to make one function that will assign focus to the textbox where the datepicker sets the date.  

The examples I have seen only work when you know the datepickers ID.  I have tried to use the class name but it does not work.


This code works IF I have the datapicker name. Obviously throughout the application there are hundreds of different names.

Bottom line I need to know the name of the textbox that datepicker assigns the date.

This code works if I know the id.

	$(function () {
		    $("#id").datepicker({
		        /* fix buggy IE focus functionality */
		        fixFocusIE: false,
		        onClose: function (dateText, inst) {
		            this.fixFocusIE = true;
		            this.focus();
		        },
		        beforeShow: function (input, inst) {
		            var result = $.browser.msie ? !this.fixFocusIE : true;
		            this.fixFocusIE = false;
		            return result;
		        }
		    }); 
		  

		});

Open in new window

0
Comment
Question by:bill_home
  • 2
3 Comments
 
LVL 43

Accepted Solution

by:
Chris Stanyon earned 500 total points
ID: 39824001
It does work with class names:

//html
<input type="text" id="date1" class="datepicker">
<input type="text" id="date2" class="datepicker">
<input type="text" id="date3" class="datepicker">
<input type="text" id="date4" class="datepicker">

//jQuery
$('.datepicker').datepicker();

Open in new window

http://jsfiddle.net/ChrisStanyon/ThSpL/
0
 

Author Comment

by:bill_home
ID: 39824300
Hello Chris,
Thanks for the input,. I went to jsFiddle. However the datePicker calendar in not displaying. I need to select a date and have it set focus to the textbox associated with the datepicker.
0
 
LVL 43

Expert Comment

by:Chris Stanyon
ID: 39824321
Seems to work fine for me - make sure you click in any of the textboxes in the bottom right had window and the calendar will pop up - select a date and it'll drop it into the correct input.

They were a little hard to see so I've added a green border.
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
AWS CLI issues with Tags 3 87
How to retrieve remote exit code when using rsh from Linux to Windows ? 13 52
Logon script fails 23 45
Need help Creating PowerShell Script 5 55
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question