Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 161
  • Last Modified:

Jquery DatePicker

I'm trying to use Jquery datepicker in an html page.

I took the example off the Jquery API, adjusted it & ran in on my web server. My revised version is attached; It works perfectly.

Then I adapted my "real" page to use it; here is the Jquery part of that page:

<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" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript" src="jquery/jquery.lightbox_me.js"></script>
      
<script>
$(function() {
$( "#adddate" ).datepicker();
});
$(function() {
$( "#datecompl" ).datepicker();
});
</script>

In the html:

<td width="12%"><input type="text" name="adddate" id="adddate" size="10"></td>

and

<td><input name="datecompl" id="datecompl" type="text" class="pt12" size="12" readonly="readonly"></td>

When you click the mouse on either input field, nothing happens.

In the FireFox Webconsole, it says:

TypeError: $(...).datepicker is not a function
referring to the line $( "#adddate" ).datepicker();

What's wrong?
jq-datepicker-test.htm
0
Richard Korts
Asked:
Richard Korts
1 Solution
 
RobOwner (Aidellio)Commented:
There's no reason to have separate init functions for jquery so change your code to this:

$(function() {
    $( "#adddate" ).datepicker();
    $( "#datecompl" ).datepicker();
});
0
 
eemitCommented:
What happens if you don't use Scheme-less URL?
It seams that this does not work if you open the html file locally!
0
 
RobOwner (Aidellio)Commented:
Yes it won't work locally because of the scheme-less URL.  If you view it locally it will try to load "file://code.jquery....."
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Brian TaoSenior Business Solutions ConsultantCommented:
Remove the line:
<script src="//code.jquery.com/jquery-1.10.2.js"></script>

Open in new window

As you have another script tag that includes jquery-latest.min.js.

And add "http:" to the other 2 lines where you have "//code........." and make them "http://code......"

then it should work.
0
 
Richard KortsAuthor Commented:
To Brian Tao,

I believe I did what you said. Doesn't work.

So I applied the same changes to the test page (that previously worked), now it doesn't work.

The revised version of that is attached.

FireFox web console gives this:

ReferenceError: jQuery is not defined jquery-ui.js:14
ReferenceError: $ is not defined

If we can get the test version to work, maybe I can try the real page

Thanks
jq-datepicker-test.htm
0
 
Richard KortsAuthor Commented:
To all,

I got the test version to work by adding this back in:

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

I also added it to the "real" page; real page does not work.

Here are the applicable elements of the real page:

<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript" src="jquery/jquery.lightbox_me.js"></script>
      
<script>
            
                  $(document).ready(function() {
                  
                        $('#button').click(function(e) {
                              $('#as_built').lightbox_me({
                                    closeClick:      true,      
                              });
                              e.preventDefault();
                        });                        

                  });
$(function() {
    $( "#adddate" ).datepicker();
    $( "#datecompl" ).datepicker();
});
                  

    </script>

HTML:

<tr>
            <td align="right">Date Completed:&nbsp;</td>
            <td><input name="datecompl" id="datecompl" type="text" class="pt12" size="12" readonly="readonly"></td>
      </tr>

FireFox Web Console says:

TypeError: $(...).datepicker is not a function (refers to the line  $( "#adddate" ).datepicker();)

Note the lightbox thing has nothing to do with this, I included it in case it was somehow connected to making it not work.

Thanks
0
 
Chris StanyonCommented:
You're including a second copy of jQuery AFTER the jQuery UI, so that will break the UI and it won't work. You need to make sure jQuery is included only once, and is included BEFORE the UI.

If this is to be run from a webserver, then it's best-practice to NOT include the protocol in the src.

You also don't need a separate $(function) block, as you've already got a document.ready - they both do the same thing. Here's a summary of what your page should look like (including the specific order of the JS includes). Tested and working fine.

<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8">
		<title>Chris Stanyon</title>

		<script src="//code.jquery.com/jquery-latest.min.js"></script>
		<script src="//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">
		$(document).ready(function() {
			$("#datecompl").datepicker();			
		});
		</script>	
	</head>
	<body>
		<input name="datecompl" id="datecompl" type="text" class="pt12" size="12" readonly="readonly">
	</body>
</html>

Open in new window

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now