Attempting to confirm the validity of my form

I have been attempting to validate my form in JSP, but unfortunately it is not working as expected. The form runs fine, however, the function 'validatemark' from my JavaScript file is not being called.

Below is a snippet of my code:

    <%@ page import = "javax.servlet.http.HttpServlet" %>
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <%@ page import= "org.akash.java.DabManager" %>
    <%@ page import= "org.akash.java.GetsSets" %>
    <%@ page import= "java.sql.ResultSet" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <script type="text/javascript" src="ValidateMark.js"></script>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>FILL IN YOUR MARKS HERE</title>

     </head>
     <body>
    <form action="MarksServlet" method="post" name="SubjectMarks" onsubmit="return(validatemark());" >

    <table cellpadding="2" width="20%" bgcolor="maroon" align="center"
    cellspacing="2">

        <tr>
            <td colspan=2>
            <center><font size=4><b>Subject Marks Form</b></font></center>
            </td>
        </tr>





     <%
     String stid= request.getParameter("identity");
     %>

     </tr>

        <tr>
            <td>ID</td>
            <td><input type="text" name="iden" id="iden" size="10" value= <%=stid %>></td>
        </tr>





     <tr>
        <td>Name</td>

            <%

            try {

        ResultSet resu= null;
        DabManager dab= new DabManager();
        resu= dab.Getsname(stid);
         if(resu.next())
         {
            String sname= resu.getString("sname");      
        %>
        <td><input type="text" name="yourname" id="yourname" size="30" value=<%=sname %>></td>
        <%
         }
        }catch(Exception e)
        {
            e.printStackTrace();
        }
       %>

        </tr>

        <tr>
            <td>Physics</td>
            <td><input type="text" name="Physics" id="Physics" size="10"></td>
        </tr>

        <tr>
            <td>Chemistry</td>
            <td><input type="text" name="Chemistry" id="Chemistry" size="10"></td>
        </tr>

        <tr>
            <td>Mathematics</td>
            <td><input type="text" name="Maths" id="Maths" size="10"></td>
        </tr>

        <tr>
            <td>Biology</td>
            <td><input type="text" name="Biology" id="Biology" size="10"></td>
        </tr>

        <tr>
            <td>
                <input type="reset">
            </td>
            <td colspan="2">
                <input type="submit" value="Submit Form" onclick ="confirms()"/>
            </td>
        </tr>
    </table>
</form> 

</body>
</html>

And here is my JavaScript code in ValidateMark.js:

    function validatemark()
{
    if( document.SubjectMarks.iden.value == "" || isNaN( document.SubjectMarks.iden.value))
       {
         alert( "Please provide a valid id!" );
         document.SubjectMarks.iden.focus() ;
         return false;
       }
       if( document.SubjectMarks.yourname.value == "" )
       {
         alert( "Please provide your Name!" );
         document.SubjectMarks.yourname.focus() ;
         return false;
       }


       if( document.SubjectMarks.Physics.value == "" || isNaN(document.SubjectMarks.Physics.value)|| document.SubjectMarks.Physics.value >100)
       {
         alert( "Please enter valid marks!!" );
         document.SubjectMarks.Physics.focus() ;
         return false;
       }

       if( document.SubjectMarks.Chemistry.value == "" || isNaN(document.SubjectMarks.Chemistry.value)|| document.SubjectMarks.Chemistry.value >100)
       {
         alert( "Please enter valid marks!!" );
         document.SubjectMarks.Chemistry.focus() ;
         return false;
       } 

       if( document.SubjectMarks.Maths.value == "" || isNaN(document.SubjectMarks.Maths.value)|| document.SubjectMarks.Maths.value >100)
       {
         alert( "Please enter valid marks!!" );
         document.SubjectMarks.Maths.focus() ;
         return false;
       } 

       if( document.SubjectMarks.Biology.value == "" || isNaN(document.SubjectMarks.Biology.value)|| document.SubjectMarks.Biology.value >100)
       {
         alert( "Please enter valid marks!!" );
         document.SubjectMarks.Physics.focus() ;
         return false;
       } 

       return true;
}


function confirms()
{
    if(validatemark()== true)
     alert("Marks Entered Successfully");
}

Answer №1

onsubmit="validate();"

then

onsubmit="validate();"

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 more concise method for accepting a collection of interfaces in TypeScript?

Issue I am facing a simplified version of a problem with my model: Here is how my model currently looks: interface Instrument { name: string; // ...more properties shared by all instruments... } interface Guitar extends Instrument { type: &q ...

"Encountered issues during compiling: X ERROR found at line 9 in the Header.js file, spanning from characters

An error occurred while compiling the module. The following message was displayed: Module not found: Error: Can't resolve '@mui/icons-material/Search' in 'C:\Users\pande\Documents\slack-clone\src\component ...

How do I save the value of a callback function in Vue data?

#I am facing an issue where the value of this.zuobiao is not being logged after I call the function that assigns a value to it. Why is this happening? getUserProfile() { uni.getLocation({ type: 'gcj02 ', geocode: true, success: (res) => ...

Highly complex regular expressions in nth-check causing inefficiencies during npm installation of react-router-dom

Feeling new and inexperienced with how to react, I attempted to execute the command "npm i react-router-dom" but it ended up stopping the download process and displaying several errors. In my search for a solution, I stumbled upon this reference to some ...

Automatically navigate through form fields using jQuery when pasting data

Enhancing the form filling experience by allowing users to prepare a text file in advance and simply copy/paste it into the form for quick submission. Integration of a feature that automatically moves to the next input field when a tab or newline character ...

Issue with Google Charts - Chart is unable to render because data table has not been defined

Using Ajax, I attempted to set an Interval for my Google Chart, but unfortunately, the Chart is not being drawn. Instead, I repeatedly receive the error message: "Data table is not defined." every 5 seconds. If you want to see a screenshot of the error mes ...

Utilizing Node.js and Express to call a function twice - once with the complete req.body and once with an empty body

Trying to articulate this may be a bit challenging, but I'll give it my best shot. I have an iOS app and Android app that both access the same node.js app through their respective web views. The iOS version is able to open the node.js app without any ...

Decode array in JavaScript

Hello, I'm currently trying to deserialize this array in JavaScript using the PHPunserialize module: a:7:{s:13:"varPertinence";a:4:{i:0;s:5:"REGLT";i:1;s:2:"13";i:2;s:2:"15";i:3;s:2:"16";}s:10:"varSegment";N;s:12:"varSSegment1";N;s:12:"varSSegment2"; ...

Looking for assistance grasping the concept of using a for loop in MongoDB's aggregate method

This code snippet is designed to maintain the order of an array (var list) when utilizing mongoDb's $in clause effectively. Although, I must admit that the logic behind it is not entirely clear to me. I can see that it's iterating in reverse to ...

The i18n feature in Nuxt 3 retrieves language locales from an external API

While working on my Nuxt 3 app, I encountered an issue when trying to integrate i18n. Despite conducting extensive research, I couldn't find any helpful information, hence I have a question. I am utilizing i18n with Prismic CMS. The locales array is s ...

Will the identifier "id" be considered unique if the element with the matching id has its display property set to "none"?

Imagine you have a DIV element in your document with the id "row". Now, if you add another DIV with the same id and change the display property of the first DIV to "none", does the id of the second DIV become unique? ...

Error encountered while rendering HTML template with Django and AngularJS due to TemplateSyntaxError

Hello, I am new to Angular and Django. I have built a Django webpage and am attempting to display values from a basic AngularJS app and controller tutorial using my HTML template. However, I keep encountering an error in the index.html file when trying to ...

Utilizing cloud functions to distort an inappropriate image

I have a requirement to analyze any uploaded image for inappropriate content and blur it if necessary. The log this image is inappropriate indicates that the detection process is working correctly. However, I am not able to see any further logs which sugg ...

Unveiling the magic: Dynamically displaying or concealing fields in Angular Reactive forms based on conditions

In my current scenario, there are three types of users: 1. Admin with 3 fields: email, firstname, lastname. 2. Employee with 4 fields: email, firstname, lastname, contact. 3. Front Office with 5 fields: email, firstname, lastname, airline details, vendo ...

Waiting for response in AngularJS Controller and setting callback

I have developed an AngularJS application with controllers.js and factories.js that I am excited about. However, I am facing a challenge when trying to manipulate the values within the controller (retrieved from the factories). The issue is that these val ...

Issue with MUI Autocomplete not showing selected name on initial option selection

I encountered a strange issue with the Autocomplete component from Material UI. Here is the code snippet in question: const [isContactListInitialised, setContactListInitialised] = useState(false); const toggleContactListInitialized = () => { setContactL ...

When I avoid using a string ref, I encounter the error message "Error: Function components are not allowed to have string refs"

Recently, I created a new component const Projects = () => { const state ={ activeItemID: 1 } const CarouselRef = useRef(null); const NextSlide = () => { CarouselRef.current.style = "opacity: 0"; } return( <Co ...

"Bringing in a Nunjucks Macro - How to Easily Use It

I've been working on a script that renders a nunjucks contact.html template with the following code: let fs = require('fs'); let nj = require('nunjucks'); var contact = fs.readFileSync('./src/contact.html',&a ...

Require help with personalizing a jQuery horizontal menu

I recently downloaded this amazing menu for my first website project By clicking the download source link, you can access the code Now, I need your kind help with two issues: Issue 1: The menu seems to be getting hidden under other elements on the page ...

Transform Material UI Typography to css-in-js with styled-components

Can Material UI elements be converted to styled-components? <Container component="main" maxWidth="XS"> <Typography component="h1" variant="h5"> Sign in </Typography> I attempted this for typography but noticed that t ...