Solved

Do I only need to include standard jQuery library for the datepicker?

Posted on 2014-11-13
16
217 Views
Last Modified: 2014-11-13
http://jqueryui.com/datepicker/

Also, I want the datpicker to popup when either the input file or a img file of a calendar is clicked.  is this how I would select the 2 item's using their id attributes?
  <script>
  $(function() {
    $( "# id-1, #id-2").datepicker();
  });
  </script>

Also, if the user selects the image instead of the input file, how do I put the selected date to the input file with id-1?

Thank you.
0
Comment
Question by:lapucca
  • 7
  • 5
  • 3
  • +1
16 Comments
 
LVL 58

Expert Comment

by:Gary
Comment Utility
No, you need the jQuery UI library as well
0
 
LVL 8

Expert Comment

by:vr6r
Comment Utility
Regarding the user clicking the image, you just need to wrap the img in a label and reference the input id in the label's "for" attribute.

Like this...
<input type="text" id="id-1" /><label for="id-1"><img src="your image path here" /></label>

Open in new window

0
 
LVL 51

Accepted Solution

by:
Julian Hansen earned 166 total points
Comment Utility
Here is a full working example
<!doctype html>
<html>
<head>
<title>Test</title>
<link rel="stylesheet" media="screen" href="css/jquery-ui.min.css" />
<script src="http://code.jquery.com/jquery.js"></script>
<script src="js/jquery-ui.min.js"></script>
<script type="text/javascript">
$(function() {
  $('.datepicker').datepicker();
});
</script>
</head>
<body>
<label for="mydate"><img src="images/date-icon.png" /></label><input type="text" class="datepicker" id="mydate"/>
</body>
</html>

Open in new window

Working sample here http://www.marcorpsa.com/ee/e067.html
0
 

Author Comment

by:lapucca
Comment Utility
Julian,
thank for the sample code.  Does it have to be the label tag or would span tag or other tags work as well?  Thank you.
0
 

Author Comment

by:lapucca
Comment Utility
Julian,
I replace the library link to try it out and now it doesn't work.  Can you see what's wrong with the jQuery link I included?  I put those urls in the browser and they all seem to show the code.  

Thank  you.

<!doctype html>
<html>
<head>
<title>Test</title>
 <link rel="stylesheet" href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>

<script src="http://code.jquery.com/jquery.js"></script>

<script type="text/javascript">
$(function() {
  $('.datepicker').datepicker();
});
</script>
</head>
<body>
<input type="text" class="datepicker" id="mydate"/><label for="mydate"><img src="http://www.marcorpsa.com/ee/images/date-icon.png" /></label>
</body>
</html>
0
 
LVL 58

Assisted Solution

by:Gary
Gary earned 167 total points
Comment Utility
The jQuery library needs to be first

<!doctype html>
 <html>
 <head>
 <title>Test</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css">
 <script src="http://code.jquery.com/jquery.js"></script>
 <script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>



 <script type="text/javascript">
 $(function() {
   $('.datepicker').datepicker();
 });
 </script>
 </head>
 <body>
 <input type="text" class="datepicker" id="mydate"/><label for="mydate"><img src="http://www.marcorpsa.com/ee/images/date-icon.png" /></label>
 </body>
 </html> 

Open in new window

0
 

Author Comment

by:lapucca
Comment Utility
Gary,
I'm not sure what do you mean.  I put this in and it still doesn't work.  I'm not sure what do you mean by jQuery library first,
thank you.
datepicker.html
0
 
LVL 58

Expert Comment

by:Gary
Comment Utility
The code should be as in my previous comment
Include the jquery library and then the jQuery UI library.

You datepicker.html now has the files in twice.

<!doctype html>
<html>
<head>
<title>Test</title>
<!--  <link rel="stylesheet" href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script> -->

<script type="text/javascript">
$(function() {
  $('.datepicker').datepicker();
});
</script>
</head>
<body>
<input type="text" class="datepicker" id="mydate"/><label for="mydate"><img src="http://www.marcorpsa.com/ee/images/date-icon.png" /></label>
</body>
</html>

Open in new window

0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:lapucca
Comment Utility
Gary, In note++ I save yours and mine file as html files.  Then select Run (Firefox) and both doesn't work when I click on input and calendar.
Thank you.
0
 
LVL 8

Expert Comment

by:vr6r
Comment Utility
Try this... explicitly defined paths to jquery-ui scripts

<!doctype html>
 <html>
 <head>
 <title>Test</title>
 <script src="http://code.jquery.com/jquery.js"></script>
 <script src="http://code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
 <link rel="stylesheet" href="http://code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css">
 
  <script type="text/javascript">
 $(function() {
   $('.datepicker').datepicker();
 });
 </script>
 </head>
 <body>
 <input type="text" class="datepicker" id="mydate"/><label for="mydate"><img src="http://www.marcorpsa.com/ee/images/date-icon.png" /></label>
 </body>
 </html> 

Open in new window

0
 
LVL 58

Expert Comment

by:Gary
Comment Utility
You had a comment tag in there.
<!doctype html>
<html>
<head>
<title>Test</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>

<script type="text/javascript">
$(function() {
  $('.datepicker').datepicker();
});
</script>
</head>
<body>
<input type="text" class="datepicker" id="mydate"/><label for="mydate"><img src="http://www.marcorpsa.com/ee/images/date-icon.png" /></label>
</body>
</html>

Open in new window

0
 

Author Comment

by:lapucca
Comment Utility
Gary,
I don't know what stupid thing I'm doing wrong but it just doesn't do anything when I clicked on eihter the calendar or the input box.  I copied you last code posted into notepad++, save as a new html file.  Click Run, From Firefox and nothing happens when I click on them..
0
 
LVL 58

Expert Comment

by:Gary
Comment Utility
This is the exact code above
http://jsfiddle.net/y5xo5nst/

Does it work? If it does then you are changing something in the code.
0
 
LVL 8

Assisted Solution

by:vr6r
vr6r earned 167 total points
Comment Utility
Lapucca, See my last reply above for your script, updated to work the way you are testing it (in notepad++ / firefox).

It was breaking because you are running the script locally on your machine which was breaking the jquery urls.  You will need to include "HTTP:" in your jquery src paths if you want to continue testing them locally this way.
0
 

Author Comment

by:lapucca
Comment Utility
Gary,
Yaaaayyy!  Finally it worked after I added http://to the path.  That was the problem and  the order of library.    Definitely learned my lesson today.  Thank you so much.
0
 

Author Closing Comment

by:lapucca
Comment Utility
Thanks everyone.  I learned so much today.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now