Marcin Calak
Marcin Calak

Reputation: 25

jQuery UI datepicker doesn't work properly

I have a problem. I want to create a calendar, that displays the date clicked on in an input box below, but I can't seem to get that working.

HTML

<div id="step3">
    <p> Choose a start date </p>
    <div id="calendar"></div>
</div>
</br>
<input type="text" name="something" value="thevalue" />

Javascript

$("#calendar").datepicker({
    inline: true,
    firstDay: 1,
    showOtherMonths: true,
    dayNamesMin: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
});
$(function(){
    $('#calendar').datepicker({
        onSelect: function(dateText, inst) {
            $("input").val(dateText);
        }
    });
});

Anyone have any tips whats wrong with my code. Here is my jsbin aswell http://jsbin.com/najunexipe/edit?html,js,output

Upvotes: 2

Views: 1227

Answers (2)

Julien
Julien

Reputation: 2756

this works :

$("#calendar").datepicker({
    inline: true,
    firstDay: 1,
    showOtherMonths: true,
    dayNamesMin: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
    onSelect: function(dateText, inst) {
      $("input").val(dateText);
    }
});

It seems like you cant initialize the plugin twice.

Upvotes: 2

Seabizkit
Seabizkit

Reputation: 2415

See changes.....

html

<!doctype html>
<html>
 <head>
 <title>Deadline Calculator</title>
 <meta charset="utf-8" />
 <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
 <meta name="viewport" content="width=device-width, initial-scale=1" />
 <link rel="stylesheet" type="text/css" href="main.css">
   <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
 <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
 <script type="text/javascript" src="script.js"></script>
 </head>

 <body>
   <input type="text" class="datepicker" id="importantthing" name="importantthing" value="" />
 </body>
</html>

javascript

$(function(){

    $('.datepicker').datepicker({
        inline: true,
        firstDay: 1,
        showOtherMonths: true,
        dayNamesMin: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
        onSelect: function(dateText, inst) {
         //$("input").val(dateText);
        }
    });
});

Upvotes: 1

Related Questions