Nes
Nes

Reputation: 591

"inst is undefined" error in jQuery UI Datepicker

I basically have a jQuery Datepicker. The Datepicker shows up but it doesn't seem functional as it does nothing when a day is selected. It doesn't work and previous and next are selected as well.

I get the "inst is undefined" error

-- the script

jQuery(function() {
    jQuery("#datepicker1").datepicker();
});

-- the element

<input type="text" id="datepicker1" name="datepicker1"/>

Upvotes: 6

Views: 7946

Answers (2)

ashenafi
ashenafi

Reputation: 21

First, you have to define the instance before calling the date picker method.

Try this,

Instatiate the datepicker

$( "#datepicker1" ).datepicker();

Then call a method on it

$( "#datepicker1" ).datepicker("show");

If you just call it without instantiating it it will throw that error.

Upvotes: 2

Nes
Nes

Reputation: 591

I found the answer.

There is a part in the page that copies the form where the element datepicker1 is included. Thus, there were multiple "datepicker1" being generated. The datepicker gets confused with the multiple datepicker1 and perhaps gets the value of the one with no value at all.

I did a fix by naming my datepicker input uniquely

<?php $x++; ?>
<input type="text" id="datepicker<?=$x;?>" name="datepicker1"/>

If you have the same problem, you might just need to make sure that all your datepickers have unique id.

Upvotes: 16

Related Questions