Solved

Jquery datepicker setting focus to textbox

Posted on 2014-01-31
3
2,447 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

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 …
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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 how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

737 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