Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"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"/>
like image 952
Nes Avatar asked Aug 23 '13 06:08

Nes


2 Answers

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.

like image 110
Nes Avatar answered Oct 03 '22 07:10

Nes


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.

like image 23
ashenafi Avatar answered Oct 03 '22 08:10

ashenafi