Solved

Datepicker not working

Posted on 2014-01-28
8
3,372 Views
Last Modified: 2014-01-29
I am looking help again.
I am trying to use JQuery datepicker and as far as I can see I following all examples word for word but nothing is happening.
Here are the scripts I am using (I also have a jstree)
 <link href="/Content/Site.css" rel="stylesheet" type="text/css" /> 

    <script src="../../Scripts/Dialog/jquery-1.9.1.js" type="text/javascript"></script>
    <script src="../../Scripts/Dialog/jquery-ui-1.10.3.custom.min.js" type="text/javascript"></script>    
    <script src="../../Scripts/jsTree/_lib/jquery.js" type="text/javascript"></script>   
    <script src="../../Scripts/jsTree/_lib/jquery.jstree.js" type="text/javascript"></script>
    <script src="../../Scripts/jsTree/_lib/jquery.cookie.js" type="text/javascript"></script>    
    
    <link href="../../Scripts/jsTree/jstree.css" rel="stylesheet" type="text/css" />
    <link href="../../Content/blitzer/jquery-ui-1.10.3.custom.css" rel="stylesheet" type="text/css" />

Open in new window

and then in my Master page I have
$(document).ready(function() {
       $(".date").datepicker();
            });

Open in new window

and in my partialView which is loaded through Ajax, I have
<%= Html.TextBoxFor(model => model.Date, new { id = "datepicker", @class = "date" })%>

Open in new window

When I go into the textbox nothing happens but when I search firebug it gives the error
TypeError: $(...).datepicker is not a function

Open in new window


I also tried using $("#datepicker").datepicker();
but get the same error
0
Comment
Question by:Niall292
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
8 Comments
 
LVL 44

Assisted Solution

by:Rainer Jeschor
Rainer Jeschor earned 250 total points
ID: 39816379
Hi,
how do you load your partial view through ajax?
In the success/complete event you have to run
$(".date").datepicker();

Open in new window

again - as the DOM was not there when you run the initial document.ready.

HTH
Rainer
0
 

Author Comment

by:Niall292
ID: 39816405
Yes,
I load my partial view by Ajax.

I will try this first thing in the morning and let you know how I get on

Thanks
0
 

Author Comment

by:Niall292
ID: 39816481
I couldn't wait until tomorrow.

I put the line into the function like
  function getAddDeviation() {          
            $.ajax({            
                type:"GET",
                url:"/Deviations/Create/" + TreeId,
                success: function(content) {  
//                    $("#hdnfld").val(TreeId);
                    $(".date").datepicker(); 
                    $("#tableVW").empty();
                    $("#dinput").html(content);  

Open in new window

but now when I try to open the partialview nothing happens but I get the same error in Firebug.
0
Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

 

Author Comment

by:Niall292
ID: 39816513
Something that might make a difference, (I'm not sure)

I open the a partial view in the  but then the Input fields are loaded as a partial view in that partial view.
I'm not sure if that might cause an issue but it was the only way I could think of doing what I was trying to accomplish
0
 
LVL 4

Accepted Solution

by:
ItWorked earned 250 total points
ID: 39816899
What I can say is,
1) Open chrome -> load your page
2) press F12 (which will open inspector window) / you can also use firebug
3) Check Resources tab
4) Are you having two jQuery.js files? (doesn't matter versions)
 in Your code folllowing line
<script src="../../Scripts/Dialog/jquery-1.9.1.js" type="text/javascript"></script>
    <script src="../../Scripts/Dialog/jquery-ui-1.10.3.custom.min.js" type="text/javascript"></script>    
    <script src="../../Scripts/jsTree/_lib/jquery.js" type="text/javascript"></script>

Open in new window


First line references to jQuery file and third file also references to the same(Correct me if I'm not wrong).

jquery-1.9.1.js file has declaration of $ function
jquery-ui-1.10.3.custom.min.js extends $ function
jquery.js again declares $ function which will overwrite the extended functionality and hence UI functions won't be available.
0
 

Author Comment

by:Niall292
ID: 39817582
Thanks for the response but I have now removed Jquery.js and it seems to make no difference

In Chrome Resources > scripts it shows

jquery-1.9.1.js
jquery-ui-1.10.3.custom
jquery.cookie.js
jquery.jstree.js

and put $(".date").datepicker(); in my ajax call but still nothing
0
 

Author Comment

by:Niall292
ID: 39817589
I rearranged the scripts and it started working, so thank you all for your help and I will divide the points out.

Thank you again
0
 

Author Closing Comment

by:Niall292
ID: 39817598
I think it was a combination of the 2 answers. Putting the $(".date").datepicker(); in my ajax call and removing the extra js file. Then also putting the files in the right order and it worked
0

Featured Post

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

734 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