• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

DatePicker works but only one per page

 
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Im writing a form in JSP like this:



I added a datePicker using jQuery at the bottom of the page. If I use one it works but when I use two only the one which is at the first place in the form shows a pop up for pick a date, the other one just doesnt show it.



Any idea?

Regards,
Isaac
 
author
Posts: 18
7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Isaac Ferguson wrote:

I added a datePicker using jQuery at the bottom of the page. If I use one it works but when I use two only the one which is at the first place in the form shows a pop up for pick a date, the other one just doesnt show it.


IDs for HTML elements must be unique. First of all, if you add two datepickers, make sure they have two different IDs. Also, you are initializing the datepicker based on the ID, which gets messy if you keep using the ID. A better approach is to initialize the datepicker based on a class if you have multiple elements on the same page.

Using a class for the datepicker makes your code look like this:
 
Angus Ferguson
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried with code like this:



And in the HEAD this:


Now it doesnt whow any of them.

Any idea?
 
Stephan Hochhaus
author
Posts: 18
7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You must change the code inside the JavaScript function to use .datepicker and not #datepicker
 
Sheriff
Posts: 67637
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you name something "fred", and then call for "barney", you should not be surprised when fred doesn't answer.

You might want to reacquaint yourself with how jQuery (and CSS) selectors work so that you know exactly what is being addressed when you use a jQuery selector.
 
Angus Ferguson
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It works now. It was the dot issue

<script>
$(function() {
$( ".datepicker" ).datepicker();
});
</script>

 
Evacuate the building! Here, take this tiny ad with you:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic