Link to home
Start Free TrialLog in
Avatar of Richard Korts
Richard KortsFlag for United States of America

asked on

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
Avatar of Rob
Rob
Flag of Australia image

There's no reason to have separate init functions for jquery so change your code to this:

$(function() {
    $( "#adddate" ).datepicker();
    $( "#datecompl" ).datepicker();
});
What happens if you don't use Scheme-less URL?
It seams that this does not work if you open the html file locally!
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....."
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.
Avatar of Richard Korts

ASKER

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
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
ASKER CERTIFIED SOLUTION
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial