2

I have a form where you can input some information and click a button which will add a replica of that form, this can be done over and over again until they are happy with the information placed.

On this form, I have two date inputs, one which is date_from and another which is date_to, these are arrays to enable more forms on this page. What I am having trouble with, is I'm using JQuery's datepicker UI and at the minute, the inputs have id's so the datepicker can only be used once.

How would I get it so that the JQuery datepicker can be used on each date input which comes up?

This is my code so far...

$(function() {
    $("#to-date").datepicker({
        dateFormat: "dd/mm/yy",
        altField: "#alt-to",
        altFormat: "yy-mm-dd"
});

    $("#from-date").datepicker({
        dateFormat: "dd/mm/yy",
        altField: "#alt-from",
        altFormat: "yy-mm-dd"
    });
});

Here's my JSFiddle, although the datepicker isn't working on this, but it is on my desktop.

Any help would be appreciated.

1 Answer 1

1

Use a class to select the inputs.

<input type="text" id="from-date"  class="from_date" value="">

$(".from_date").datepicker({...});

Edit With the updates (through the comment on my answer) question I found the solution here.

You can use JQuery selectors in the altField to get to the input you want the date to be shown in.

Sign up to request clarification or add additional context in comments.

4 Comments

That doesn't work, as I have a hidden field which it's meant to update and using just one updates all of the hidden fields relevant to the field which was clicked on.
Sorry, I forgot the mention about there are hidden fields within the form as well. Everytime someone clicks on the add a form button it will give out two fields which can be seen and two which are hidden. I need the two which can be seen to update the two hidden fields corresponding to the two which you see. This needs to be completely dynamic some how.
Then I think you'll find your answer here
Thank you for that comment, it has helped me out. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.