Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

set today date in jquery datepicker on html reset button

Posted on 2014-03-21
3
Medium Priority
?
4,154 Views
Last Modified: 2014-03-21
Hi,
I need to set today date in jquery date picker on click of reset button?

On load i have

 
$(function() {
    $( "#datepicker" ).datepicker({
      showOn: "button",
      buttonImage: "images/calendar.gif",
      buttonImageOnly: true,
      dateFormat:'dd/mm/yy',
      
    }).datepicker("setDate", "0");
  });

Open in new window

it works fine (today date is displayed in the text box).
Now i click reset button the value is removed,how to set the today date?
i tried with below codes but no luck
 
$(function() {
		    $( "#datepicker" ).datepicker({

		    }).datepicker("setDate", "0");
		  });


$("#datepicker").datepicker("setDate", "0");

Open in new window

0
Comment
Question by:Rocking
  • 2
3 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 39946162
try this :
$(function() {

    var dp = $( "#datepicker" ).datepicker({
      showOn: "button",
      buttonImage: "images/calendar.gif",
      buttonImageOnly: true,
      dateFormat:'dd/mm/yy',      
    });

    function setToday() {
         dp.datepicker("setDate", "0");
    } 
    setToday();

    $("form").on("reset", setToday);

  });

Open in new window

0
 

Author Comment

by:Rocking
ID: 39946186
thanks for quick response but not working
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 600 total points
ID: 39946430
Work with a small timer : http://jsfiddle.net/5rpty/1/
jQuery(function($) {

    var dp = $( "#datepicker" ).datepicker({
      showOn: "button",
      buttonImage: "images/calendar.gif",
      buttonImageOnly: true,
      dateFormat:'dd/mm/yy',      
    });

    function setToday() {
        setTimeout(function() {
             dp.datepicker("setDate", "0");
        }, 200); // try to decrease to 10ms
    } 
    setToday();

    $("form").on("reset", setToday);

});

Open in new window

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
The viewer will learn how to dynamically set the form action using jQuery.
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)
Suggested Courses

916 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