Solved

Jquery datepicker setting focus to textbox

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

808 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