jquery - Javascript datepicker usage in html -


can correct date picker code, want display dates 2013 2014 in tried this, works sometime shows 2004, 2024 also, please me correct , simplify code, , want create php function display date range in want enter min , max datepick('2013-01-01','2014-01-01')

this code, bug

html

<div id="date">      <h1 id="dts"><br>select date</h1>      <label bottom="360px"> <b>from</b>&nbsp&nbsp&nbsp         <br>     </label>     <input type="text" id="from" name="from">     <br>     <label> <b>to</b>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</br>     </label>     <input type="text" id="to" name="to"> </div> 

javascript

$(function () {     $("#from").datepicker({         dateformat: 'dd-mm-yy',         changemonth: true,         changeyear: true,         numberofmonths: 1,         maxdate: new date('2014-12-31'),         mindate: new date('2013-01-01'),         onclose: function (selecteddate) {             $("#to").datepicker("option", "mindate", selecteddate);         }     });      $("#to").datepicker({         dateformat: 'dd-mm-yy',         changemonth: true,         changeyear: true,         numberofmonths: 1,         maxdate: new date('2014-12-31'),         mindate: +0,         onclose: function (selecteddate) {             $("#from").datepicker("option", "maxdate", selecteddate);         }     }); }); 

jsfiddle
jsfiddle/results

in fiddle from range coming in browser showing 2024 also.

inthe onclose function, check date selected before using selecteddate:

$(function () {     $("#from").datepicker({         dateformat: 'dd-mm-yy',         changemonth: true,         changeyear: true,         numberofmonths: 1,         maxdate: new date('2014-12-31'),         mindate: new date('2013-01-01'),         onclose: function (selecteddate) {             if (selecteddate) {                 $("#to").datepicker("option", "mindate", selecteddate);             }         }     });      $("#to").datepicker({         dateformat: 'dd-mm-yy',         changemonth: true,         changeyear: true,         numberofmonths: 1,         maxdate: new date('2014-12-31'),         mindate: +0,         onclose: function (selecteddate) {             if (selecteddate) {                 $("#from").datepicker("option", "maxdate", selecteddate);             }         }     }); }); 

fiddle

another option use onselect instead of onclose, triggered when user selects date.

fiddle


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -