#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2006
    Posts
    7
    Rep Power
    0

    Question JQuery function error


    Hi there,

    I am very new to JQuery and found a great function that adds days to a date. Here is the link to the working Jfiddle example

    Edit fiddle - JSFiddle

    I took this code so that I could test it locally but it will not function. The error I am getting is

    SCRIPT5009: '$' is undefined test.html (19,1)
    SCRIPT7002: XMLHttpRequest: Network Error 0x3, The system cannot find the path specified.

    Here is the source that I took from the Jfiddle example

    Any advice on this would be really helpful as I have been chasing my tail for a while now.

    Thanks for looking.

    Code:
    <!DOCTYPE html>
    <html>
    <head>
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <meta name="robots" content="noindex, nofollow">
      <meta name="googlebot" content="noindex, nofollow">
      <script type="text/javascript" src="//code.jquery.com/jquery-2.1.0.js"></script>
    <link rel="stylesheet" type="text/css" href="/css/result-light.css">
    
      <title></title>
    
      
        
    
    
    
    
    <script type='text/javascript'>//<![CDATA[
    $(window).load(function(){
    ;(function($, window, document, undefined){
        $("#days").on("change", function(){
           var date = new Date($("#start_date").val()),
               days = parseInt($("#days").val(), 10);
            
            if(!isNaN(date.getTime())){
                date.setDate(date.getDate() + days);
                
                $("#end_date").val(date.toInputFormat());
            } else {
                alert("Invalid Date");  
            }
        });
        
        
        //From: http://stackoverflow.com/questions/3066586/get-string-in-yyyymmdd-format-from-js-date-object
        Date.prototype.toInputFormat = function() {
           var yyyy = this.getFullYear().toString();
           var mm = (this.getMonth()+1).toString(); // getMonth() is zero-based
           var dd  = this.getDate().toString();
           return yyyy + "-" + (mm[1]?mm:"0"+mm[0]) + "-" + (dd[1]?dd:"0"+dd[0]); // padding
        };
    })(jQuery, this, document);
    });//]]> 
    
    </script>
    
      
    </head>
    
    <body>
      <input type="date" id="start_date" placeholder="Start Date"/>
    <input type="number" id="days" placeholder="Days"/>
    <input type="date" id="end_date" placeholder="End Date" readonly/>
      
      <script>
      // tell the embed parent frame the height of the content
      if (window.parent && window.parent.parent){
        window.parent.parent.postMessage(["resultsFrame", {
          height: document.body.getBoundingClientRect().height,
          slug: "MCzJ6"
        }], "*")
      }
    </script>
    
    </body>
    
    </html>
  2. #2
  3. Wiser? Not exactly.
    Devshed God 2nd Plane (6000 - 6499 posts)

    Join Date
    May 2001
    Location
    Bonita Springs, FL
    Posts
    6,112
    Rep Power
    4103
    SCRIPT5009: '$' is undefined test.html (19,1)
    That means you failed to load the jQuery library.

    If what you pasted is exactly what you have in your test file then the script tag is there, so the import would have failed for some other reason such as no internet connection or being blocked by a filter.
    Recycle your old CD's



    If I helped you out, show some love with some reputation, or tip with Bitcoins to 1N645HfYf63UbcvxajLKiSKpYHAq2Zxud

IMN logo majestic logo threadwatch logo seochat tools logo