Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 342537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:48:49+00:00 2026-05-12T10:48:49+00:00

Thanks for taking the time to read this. I have an unknown number of

  • 0

Thanks for taking the time to read this.

I have an unknown number of (dynamically inserted) input elements in a form, to each of which I want to attach the datepicker widget included in jQuery UI.

All of the input elements that I want to attach the datepicker to have a class of “date-pick”. Obviously because we have more than one matching element we need more than just a class name so that the date value gets returned to the originating field rather than just the first match.

Ordinarily I’d probably just do something like:

$("input.date-pick").each(function(){
    $(this).datepicker({dateFormat: "yy-mm-dd"});
});

However in the code I’m working with, the input elements do not have unique IDs until the form data is saved (something that I’m unable to change), though they do have unique name attribute values of the format name="field_id_x[y][z]" which, when the form is saved then gets converted to an id of the format id="field_id_xyz".

So my question is, can anyone show me how to loop through all the input elements with a class of “date-pick” based on their name attribute values?

(PS It might also be worth mentioning that the number of matching input elements in the form can be increased/decreased by the user on the fly.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T10:48:49+00:00Added an answer on May 12, 2026 at 10:48 am

    The date picker doesn’t need the elements to have an ID. You’re already looking up the elements for it. This should work:

    $('input.date-pick').datepicker({dateFormat: "yy-mm-dd"});
    

    Note you don’t even need the each call.

    Complete example:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    <title>DatePicker Test Page</title>
    <script type="text/javascript" src="http://jqueryui.com/latest/jquery-1.3.2.js"></script>
    <script type="text/javascript" src="http://jqueryui.com/latest/ui/ui.core.js"></script>
    <script type="text/javascript" src="http://jqueryui.com/latest/ui/ui.datepicker.js"></script>
    <script type='text/javascript'>
    $(function() {
        $('.dp').datepicker();
    });
    </script>
    </head>
    <body>
    <hr />
    <input class='dp' type='text'>
    <input class='dp' type='text'>
    <input class='dp' type='text'>
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Thanks everyone for taking the time to read this. I have styled my navigation
First, thanks in advance for taking the time to read through this. I have
thanks for taking the time to read this. I have a JavaScript (jQuery) navigation
I just first want to say, thanks for taking the time to read this!
Thanks in advance for taking the time to read this. Apologies that it is
First, thanks for taking the time to read this. I'm having some difficulties with
Thanks for taking the time to read this. I am trying to create a
Thanks for taking the time to read this! Well, this is what I am
Firstly, thanks for taking the time to read and possibly comment on this question.
Hello everybody and thanks for taking the time to read this ; I was

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.