When using JavaScript's Date() function, it may sometimes return an

I am currently developing a website that calculates the time elapsed since a specific date. However, when I input the parameters provided by the user and call new Date(), it displays "Invalid Date".

This is the code snippet I have been using: http://jsfiddle.net/8VkBu/ (please note that the CSS may appear distorted in the small window)

I would like to understand why it is showing "Invalid Date" and what steps I can take to resolve this issue.

Appreciate your assistance, Fjpackard.

Answer №1

I have made updates to your JS FIDDLE example

Please review the changes.

Your code should now look like this:

y = parseInt($("#year").val());
m = parseInt($("#month").val()) - 1;
d = parseInt($("#day").val());
h = parseInt($("#hour").val());

instead of

y = parseInt($("#years").val());
m = parseInt($("#months").val()) - 1;
d = parseInt($("#days").val());
h = parseInt($("#hours").val());

This correction was necessary because the input id in the HTML form is in singular form,

while in your jQuery code you were using plural form.

For instance, in the HTML you used 'year' and in the jQuery you used 'years'

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

jQuery functions correctly within jsfiddle, yet it encounters issues when utilized within WordPress

I've been experimenting with a jQuery script to grey out the screen. While it works perfectly on my jsFiddle link provided below, I'm having trouble getting it to work from within my WordPress plugin. Check out the working script on my jsFiddle ...

Creating a seamless design with a navigation brand and login button on the same row within a navbar

I am trying to create a fixed navbar at the top of my webpage. The goal is to have the company's logo and name on the left side, with a log-in button on the right side. After reviewing multiple examples online, I found that most of them use a navbar- ...

Error encountered with Content Security Policy while utilizing react-stripe

I am currently in the process of developing a React application that incorporates Stripe payments utilizing the @stripe/react-stripe-js (version "^1.9.0") and @stripe/stripe-js (version "^1.32.0") npm packages. While the payments are functioning correctly, ...

Achieve full width for container using flexbox styling

In an attempt to develop a category dropdown menu with multiple columns based on the length of the <ul>, I am facing some challenges. For reference, you can view the fiddle that I have created here. The goal is to arrange each submenu item below th ...

Reposition DIV elements using only CSS styling

I'm attempting to switch the positions of two divs for responsive design (the website appearance changes based on browser width, ideal for mobile). Currently, my setup looks like this: <div id="first_div"></div> <div id="second_div"&g ...

Loading events for a fullCalendar in node.js using the jade library

I successfully integrated fullCalendar into my nodeJS application using jade and Express, and I have managed to load the calendar. Within the jade file, I pass an array containing events information. How can I display these events on the calendar within th ...

using async.waterfall with async.apply

Here is a code snippet that I am working with: async.waterfall([ // Read directory async.apply(fs.readdir, '../testdata'), // Load data from each file function(files, callback) { async.each(files, loadDataFromFile, callback); } ], ...

The persistent issue of window.history.pushstate repeatedly pushing the identical value

I need some assistance with my Vue application. I am trying to update the URL when a user clicks on an element: const updateURL = (id: string) => { window.history.pushState({}, '', `email/${id}`); }; The issue I'm facing is th ...

The display message in Javascript after replacing a specific string with a variable

I'm currently working on a task that involves extracting numbers from a text input, specifically the first section after splitting it. To test this functionality, I want to display the result using an alert. The text input provided is expected to be ...

The JSP page is unable to locate or access relative resources such as CSS stylesheets and images

I'm struggling to create a basic web page using JSP. The issue I'm facing is that no resources, such as images or CSS, are being found regardless of the URL I use. Here is my simple JSP code: <%@ page language="java" contentType="text/html; ...

I'm seeking assistance in understanding the malfunction of this particular function

I am struggling to create a basic function that is supposed to check whether a value is a number and not greater than 100. I'm confused as to why it's not working. Can someone explain if mixing jQuery and JavaScript is causing the issue? $(' ...

What is the encoding for Javascript in UTF-8?

My current ajax call is able to successfully send the request and retrieve the expected response. However, I am facing difficulty in correctly displaying it in li items. $.ajax({ url: "{% url 'users:profile_page_tags_get' 'primary&apos ...

Unable to locate module in Node.js - module.js

I encountered an error while running the node server which states: $ node server.js module.js:339 throw err; ^ Error: Cannot find module './server/routes' at Function.Module._resolveFilename (module.js:337:15) at Function.Module ...

Encountering difficulties retrieving information from an API using Angular

I am encountering an issue while trying to retrieve data from an API. When I use console.log() to view the data, it shows up in the console without any problem. However, when I attempt to display this data in a table, I keep receiving the error message: ER ...

Subsequent jquery functions fail to work following a smooth ajax operation

MODIFY JQUERY-AJAX REQUEST CODE: <script type="text/javascript"> $(document).ready(function(){ $(".form").submit( function(e) { e.preventDefault(); var form = $(this); var div_add_comment = $(form).parent(); var div_comments = $(div ...

JavaScript: The function is encountering issues with properly formatting the numbers

I am currently facing an issue with a function I have created to format numbers for currency by inserting commas every 4 digits. The problem lies in the fact that the first 4 numbers do not have a comma added where it should be, and the formatting only wor ...

Having issues with the functionality of the Material UI checkbox component

Having issues with getting the basic checked/unchecked function to work in my react component using material UI checkbox components. Despite checking everything, it's still not functioning as expected. Can someone please assist? Here's the code s ...

Safari experiences a decrease in speed when multiple checkbox elements are present

While using Safari, I have encountered a problem. The performance of interacting with a text input is significantly affected when there are numerous type="checkbox" elements on the page. This issue appears to be more pronounced in Safari compared to Chrom ...

Revamping the values attribute of a table embedded in a JSP page post an AJAX invocation

I am encountering an issue with displaying the content of a table. The table's data is retrieved via an AJAX request when clicking on a row in another table on the same page. Here is my code for the JSP page: <table id="previousList" class="table" ...

There is a runtime error in Microsoft JScript, as the object does not support the property or method '__defineGetter__'

Upon opening my project in IE9, I encountered the error message: "Microsoft JScript runtime error: Object doesn't support property or method 'defineGetter'." Can anyone provide guidance on how to resolve this issue? ...