INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Function issue JQuery

Function issue JQuery

(OP)
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

http://jsfiddle.net/MCzJ6/1/

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> 

RE: Function issue JQuery

Hi

The code you posted works for me.

The code you posted may be irrelevant as the 2nd error talks about XMLHttpRequest which not seems to be related.

Feherke.
feherke.github.io

RE: Function issue JQuery

(OP)
Hi, thank you for the reply.

Could you tell me what browser you are using please?

RE: Function issue JQuery

Hi

  • Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:56.0) Gecko/20100101 Firefox/56.0
  • Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/61.0.3163.100 Chrome/61.0.3163.100 Safari/537.36
Also parsed with my good old pair of eyes and they also confirmed there can be no such error like those you quoted.

Feherke.
feherke.github.io

RE: Function issue JQuery

(OP)
Thanks for the reply. Very strange, in IE, Edge and firefox the example here works fine http://jsfiddle.net/MCzJ6/1/ but with the sample code I pasted and load locally, the end_date does not get set when I add some days.

I will keep trying to troubleshoot. Thanks again for looking.

RE: Function issue JQuery

Hi

Ah ! I think I got what you did. You open it directly from the file system with file: protocol. For me it worked because I requesting it from my local HTTP server as http://localhost/craigward.html.

Then your problem is with the protocol-less URL :

CODE --> HTML ( fragment )

<!--
no protocol specified to inherit from the page :
  * when used in page http://jsfiddle.net/MCzJ6/1/ jQuery will be loaded from http://code.jquery.com/jquery-2.1.0.js
  * when used in page https://jsfiddle.net/MCzJ6/1/ jQuery will be loaded from https://code.jquery.com/jquery-2.1.0.js
  * when used in page file://yourhome/test.html will fail
-->
<script type="text/javascript" src="//code.jquery.com/jquery-2.1.0.js"></script>

<!--
protocol specified :
  * when used in page http://jsfiddle.net/MCzJ6/1/ jQuery will be loaded from http://code.jquery.com/jquery-2.1.0.js
  * when used in page https://jsfiddle.net/MCzJ6/1/ some browsers will refuse to load mixed in content from insecure source
  * when used in page file://yourhome/test.html jQuery will be loaded from http://code.jquery.com/jquery-2.1.0.js
-->
<script type="text/javascript" src="http://code.jquery.com/jquery-2.1.0.js"></script> 

Feherke.
feherke.github.io

RE: Function issue JQuery

(OP)
Thank you feherke that was exactly the issue! Really appreciate the help.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close