Solved

set today date in jquery datepicker on html reset button

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

729 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