Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

set today date in jquery datepicker on html reset button

Posted on 2014-03-21
3
Medium Priority
?
4,030 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
[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 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

Use Filtering Commands to Process Files in Linux

Learn how to manipulate data with the help of various filtering commands such as `cat`, `fmt`, `pr`, and others in Linux.

Question has a verified solution.

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

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…
Suggested Courses

688 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