views:

186

answers:

2

hi, here is my problem:

<input type="text" class="datepick1" id="date" />
<input type="text" class="datepick2" id="date" />
<input type="text" class="datepick3" id="date" />

then i apply datepicker on dom (by classname)

$('.datepick1').datepicker();
$('.datepick2').datepicker();
$('.datepick3').datepicker();

=> the three dom have datepicker but, onselect date, it change automatically the first one (datepick1)

HELP

+9  A: 

Your three inputs have the same id attribute on them. You can't do that, id attributes must be unique within the document. (Having the same name, on the other hand, is fine in forms -- and common, for instance for radio buttons.)

Edit So your code posted to the comment below wants to be changed to:

$('<td></td>').append(
    $(NewLivraison.template.date)
        .val(arguments.date_livraison)
        .attr('id','date_' + arguments.num) // <== Note it's "id" we're making unique
        .addClass('date_' + arguments.num)  // <== You can probably drop this entirely
        .datepicker()
).css('vertical-align','top');
T.J. Crowder
so,i have a loop (for(i=0;i<x;i++)) to add <tr> to a table (with many td), in each td i have an input id = date, and an UNIQUE class ('datepick'+i) then i apply a datepicker to each input after append. Here is a bit source code[...]append( $('<td></td>') .append($(NewLivraison.template.date).val(arguments.date_livraison) .attr('id','date') .addClass('date_'+arguments.num) .datepicker() ).css('vertical-align','top') )
namezero
this add a datepicker to my input but if i select a date it change the first input (in first tr), but if i change the ID from 'date' to 'date_'+arguments.num => this work, this is how i resolved my problem...Conclusion : if you apply a datepicker to an element, be sure that there is no other element in your page that have the same ID
namezero
btw, NewLivraison.template.date is something like "<input type=text/>
namezero
@namezero: But the point is, it doesn't matter if the *class* is unique, the *id* has to be unique, not the class. Classes don't have to be unique to each element (and are somewhat pointless if they are). Somewhere in that code above you have `.attr('id', 'date')` -- **that's** where your problem is, you need each one to have a *different* ID.
T.J. Crowder
+4  A: 

Supposed to be like this

<input type="text" id="datepick1" class="date" />
<input type="text" id="datepick2" class="date" />
<input type="text" id="datepick3" class="date" />

$('.date').datepicker();
Ergec