Solved

Jquery datepicker setting focus to textbox

Posted on 2014-01-31
3
2,305 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

930 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now