Solved

set today date in jquery datepicker on html reset button

Posted on 2014-03-21
3
3,490 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
Comment Utility
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
Comment Utility
thanks for quick response but not working
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 150 total points
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
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…

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

6 Experts available now in Live!

Get 1:1 Help Now