The Date validation script in Javascript is malfunctioning

I encountered an issue where the script I used in my HTML file didn't work as expected. The purpose of this script was to prevent users from submitting a date greater than today's date. Interestingly, when I copied the same script to another HTML file, it worked perfectly fine. It seems like there is something specific to this particular HTML file that is causing the problem.

function checkform() {
  answ = validateDate(document.getElementById("doa").value);
  if (answ == false) {
    return false;
  } else {
    return true;
  }

}

function validateDate(doa) {
  var d = new Date(doa);
  var n = new Date();
  if (d >= n) {
    alert("Date cannot be greater than today.");
    return false;
  }
  return true;
}
.welcome {
  font-weight: bold;
  font-family: Calibri;
  width: 100%;
  text-align: center;
}

.rating {
  text-align: center;
}

.particulars {
  text-align: center;
  font-weight: bold;
  font-style: italic;
}
...
...

<head>
...
...
</body>

I am curious to investigate the reason behind the malfunction of the script in my HTML file. Your insights would be greatly appreciated.

Warm regards, Mark

Answer №1

It seems like you closed the tag incorrectly. Here is the correct format:

<!--Details-->
<form action="feedbackresult.html" onsubmit="return checkForm()">
    <table class="form">
        <tbody>
            <tr>
                <td>
                    <label for="firstname">First Name: </label>
                </td>
                <td>
                    <input type="text" name="first" id="firstname">
                </td>
            </tr>
            <tr>
                <td>
                    <label for="lastname">Last Name: </label>
                </td>
                <td>
                    <input type="text" name="last" id="lastname">
                </td>
            </tr>
            <tr>
                <td>
                    <label for="mobileNo">Mobile Number:* </label>
                </td>
                <td>
                    <input type="tel" name="hpno" id="mobileNo" placeholder="e.g 91234567" maxlength="8" minlength="8" required="">
                </td>
            </tr>
            <tr>
                <td>
                    <label for="doa">Date of Appointment:* </label>
                </td>
                <td>
                    <input type="date" name="date" id="doa" min="2000-01-01" required="">
                </td>
            </tr>
        </tbody>
    </table>
</form>

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

Is there a way to use the onclick event to open a link in the same window and tab?

I am facing a challenge with a webpage containing multiple divs. I am trying to extract data from my database and display it within specific divs on the page. Additionally, I want this information to be presented when clicking on a link taking me back to t ...

Store the Ajax response in localStorage and convert it into an object for easy retrieval and manipulation

I'm currently working on an Ajax request that retrieves JSON data from the server and then stores it in localStorage for use in my application. However, I feel like my current code may not be the most efficient way to accomplish this task, as I have t ...

Dealing with reactive form controls using HTML select elements

I am working with a template that looks like this: <form [formGroup]="form"> <mdl-textfield type="text" #userFirstName name="lastName" label="{{'FIRSTNAME' | translate}}" pattern="[A-Z,a-zéè]*" error-msg ...

Is there a way to showcase posts with a certain tag in a single column on my tumblr theme, while reserving the other column for posts aimed at the wider audience?

I am interested in customizing my theme so that one section on the homepage of my blog only shows posts with a specific tag (such as "mine" or "personal"), while another section displays all posts, regardless of tags. Although I have searched through simi ...

Swapping out video files with varying quality using HTML5 and Jquery

Objective: Implementing a feature to change the video being played when a user clicks a button using Jquery. Example website for reference: (click on the "hd" button in the player control) More details: When the page loads, the browser will play the fi ...

Tips for separating the 'title' and 'icon' elements within Bootstrap panels?

I am currently working on integrating a FAQ section into my website (not yet live, so I cannot provide a link). However, I am facing some minor CSS issues that I am struggling to resolve. The problem lies in a panel that is meant to display as shown below: ...

Define the width of jqgrid

I have been utilizing SmartAdmin jqgrid to showcase data in tabular format. The number of columns in the datatable changes dynamically each time. I am converting the DataTable to a JSON object and assigning it to the jqgrid. However, it appears that jqgrid ...

Using the ternary operator in various CSS rules

Inside a .hover() function, I've written the code below: $(this).css('background-position', circle.includesXY(e.pageX, e.pageY) ? 'bottom' : ''); I'm wondering how to include additional property:value pairs within ...

Learn how to automatically navigate to another page upon successfully creating an account and setting a value in the Firebase database

I am working on a system where, after successfully creating an account and setting a value in Firebase database, the user will be redirected to another page. Currently, I have managed to navigate to the next page but I am facing an issue with setting the ...

Will the rel attribute work in all web browsers and with all HTML tags?

Confirming that it is compatible for use with JQuery scripting. ...

populate form fields with database data using ajax

I'm currently working on populating form fields with data from a database using ajax and jQuery in my Codeigniter project. I have been able to retrieve and alert the database values into an array, which you can see in this image: alert of the data arr ...

"Troubleshoot: jQuery UI accordion not functioning properly in response to

I've encountered an issue with the accordion functionality while working with dynamic data. To address this, I'm incorporating JavaScript to generate <div> and <h3> tags for the accordion. Here is the code snippet I am using: $(&ap ...

Facing issues with the forEach method in ReactJs when attempting to access data from an array

Struggling with a ReactJS issue, I've come across a problem with the HomePage Component where the forEach method isn't working as expected. I'm attempting to retrieve data from a defined array. Take a look at the code snippet below: import R ...

Error: Incompatibility - The variable is not functioning properly in node.js or express.js

Upon encountering the error message "TypeError: undefined is not a function," I called a callback with parameters null, array_reply, and threadResults. It appears that this section of code is problematic, but I am uncertain why. Your assistance in resol ...

Preventing automatic recompilation in Angular when there are changes in the assets folder

I am facing an issue while attempting to download a file generated from a Spring Boot application in the assets folder of an Angular project. Every time I call the Spring API from Angular services, the Angular CLI recompiles the project after creating the ...

Is there a way to attach a CSS class to a BoundField in order to locate it using jQuery?

I need to assign a specific class name to certain BoundFields within the GridView control. This way, after the GridView has been populated with data and displayed, I would like to have something similar to the following: <td class="Tag1">Some data c ...

Modify the color of the background for a flex-wrap list

I am facing a situation where I have a list with an unknown number of items, but I need to control the height of its container. To achieve this, I am using flex-flow: wrap column to split the list. The list starts off hidden and is displayed using jQuery&a ...

Angular ngx-translate not displaying image

My Angular application is utilizing ngx-translate to support multiple languages. I am trying to dynamically change an image based on the language selected by the user. However, I am facing difficulty in updating the image when a language is clicked. The ap ...

Error: Undefined variable in JavaScript obfuscation

My website has several small JavaScript files that I currently merge into one file and then minimize using terser. The website functions perfectly with the minimized version. Now, I want to take it a step further and obfuscate the code using JavaScript-Ob ...

Error: The validation of a JSON request failed as schema.validate is not a recognized function

As a beginner, I am currently immersed in a node.js API authentication tutorial. Everything was going smoothly until I had to refactor my code into separate files. Now, every time I send a JSON request via Postman, I keep encountering the error message "Ty ...