I have a little problem with some jQuery code.
In my page I have the following layout :
[X] "Some text" [textarea]
[X] "Some text 2" [textarea]
[X] "Some text 3" [textarea]
So basically, it’s just some checkboxes and some textarea (which is a date-picker in fact), and the code is the following (generated in PHP) :
<input type="checkbox" class="pack_check" disabled="disabled" name="id_pack[]" value="0 />
Some text
<input name="date-pack[]" id="date-pack[]" class="date-picker">
<input type="checkbox" class="pack_check" disabled="disabled" name="id_pack[]" value="1 />
Some text 2
<input name="date-pack[]" id="date-pack[]" class="date-picker">
The thing is, I want that when the user uncheck a checkbox, the associated date (in the textarea input) get an empty value…
I achieved this by doing something like that :
$('input.pack_check').change(function () {
$("input[name='date-pack[]']").val("");
});
But when I do this, ALL the textarea are being erased.
Any idea?
you cannot redeclare an ID once you used it once in the document – if you do, you will see some very non-standard behaviour like the one you’re experiencing
this is what I’d do: