Solved

Jquery datepicker setting focus to textbox

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

Accepted Solution

by:
Chris Stanyon earned 500 total points
Comment Utility
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
Comment Utility
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 42

Expert Comment

by:Chris Stanyon
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

763 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

12 Experts available now in Live!

Get 1:1 Help Now