Solved

set today date in jquery datepicker on html reset button

Posted on 2014-03-21
3
3,558 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 150 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

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 HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult 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 code hide show and toggles. 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…

863 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

18 Experts available now in Live!

Get 1:1 Help Now