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 4624144
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:05:18+00:00 2026-05-22T03:05:18+00:00

I use the JQuery datepicker , and the problem is that I generate the

  • 0

I use the JQuery datepicker, and the problem is that I generate the HTML, so I don’t know in advance the ID’s of the fields.

My code can be tried at http://jsfiddle.net/littlesandra88/KrEqk/

The forms below are generated, where the ID’s just get prefixed with a random number to make them different.

What I did to get datepicker in those fields was to add class="datepick" to those fields like so

<input name="from" id="114_begin_date" value="16/05-2011" type="text" class="datepick" />
<input name="to"   id="114_end_date"   value="16/05-2011" type="text" class="datepick" />

and add .datepick to the inline datepicker JavaScript, like so

var dates = $("#from, #to, .datepick").datepicker({         

If you try to change the dates several times you will notice, that all fields are updated =(

How do I prevent that from happening, so just the field that I click on is changed?

  • 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-22T03:05:19+00:00Added an answer on May 22, 2026 at 3:05 am

    The problem is in the onSelect handler

    You are running

    dates.not(this).datepicker("option", option, date);
    

    this changes all the other datepickers to a single value (the one of the current datepicker)..


    Update for comment

    change your onSelect method to

    onSelect: function(selectedDate) {
                      var self = this;
                      var option = this.name == "from" ? "minDate" : "maxDate",
                      instance   = $(this).data("datepicker"),
                      date       = $.datepicker.parseDate(
                                      instance.settings.dateFormat || $.datepicker._defaults.dateFormat, selectedDate, instance.settings);
                      dates.filter(function(){return this.form === self.form;}).not(this).datepicker("option", option, date);
                   } 
    

    changes made

    1. added the var self = this; for later use
    2. use the name attribute instead of the id to decide which limit to use
    3. instead of applying the new date limit to all other datepickers (i assume you took that part from somewhere where only two datepickers existed), we filter them down to the ones that are in the same form as the one we changed. (in effect the other one, in the same line. Keep in mind that this works only for two datepickers per form named from and to)

    demo at http://jsfiddle.net/gaby/Wy6qT/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I use jquery to remove a SPECIFIC div that has no children
I'm trying to use the jquery datepicker - http://jqueryui.com/demos/datepicker/ in a custom control (.ascx).
I'm tyring to style the jQuery datepicker. I can't use a jQuery theme as
I'm trying to use the following plugin for date picking: http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/index.html And I'm trying
http://jsfiddle.net/r7D2x/ I'm trying to use jQuery Datepicker on a label ( <span> ) instead
I have an MVC3 application, I know that for relative paths, I can use
How do I use the jQuery Datepicker with a textbox input: $(#my_txtbox).datepicker({ // options
I'm trying to use jQuery to format code blocks, specifically to add a <pre>
I am begging to use jquery. I have the following call that works in
I hava a jQuery UI datepicker which I intend to use with a textbox

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.