I have cretaed a JSP page that has 4 textboxes that need to be validated. 2 are text and 2 are integers. I have tried using the jQuery validation tool but that didn't work out so well. I will provide my JSP code and my script. Can someone help me out?

<%@page import="java.util.List"%> <%@page import="jonej102.Product"%> <%@page contentType="text/html" pageEncoding="UTF-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Inventory</title> </head> </script> <body> <h1>View Inventory</h1> <jsp:useBean id="inventoryBean" class="jonej102.InventoryManager"></jsp:useBean> <table border="1" cellspacing="10"> <th>UPC</th> <th>Long Details</th> <th>Short Details</th> <th>Price ($)</th> <th>Quantity</th> <th></th> <th></th> <c:forEach var="product" items="${inventoryBean.getProductList()}"> <form action="inventory" method="POST"> <tr> <td><input type="text" name="upc" value="${product.getUpc()}" size="10" /></td> <td><input type="text" name="longDetails" value="${product.getLongDetails()}" size="50" /></td> <td><input type="text" name="shortDetails" value="${product.getShortDetails()}" size="20" /></td> <td><input type="text" name="price" value="${product.getPrice()}" /></td> <td><input type="text" name="stock" value="${product.getStock()}" size="4" /></td> <td><input type="submit" name="button" value="Update" /></td> <td><input type="submit" name="button" value="Delete" /></td> </tr> </form> </c:forEach> </table> <br /> <h1>Manage Inventory</h1> <form method="POST" action="inventory">
            UPC: <input type="text" name="upc" size="10" /> <br /><br />
            Long Details: <input type="text" name="longDetails" size="50" /> <br /><br />
            Short Details: <input type="text" name="shortDetails" size="20" /> <br /><br />
            Price: $<input type="text" name="price" /> <br /><br />
            Stock: <input type="text" name="stock" size="4" /> <br /><br /><br /> <input type="submit" name="button" value="Create" /> </form> </body> </html>



This is my script

function validateMyForm()

    {

        var valid = true;

        var validationMessage = 'Please correct the following errors:\r\n';





        if (document.getElementById('upc').value.length == 0)

        {

            validationMessage = validationMessage + '  - UPC is missing\r\n';

            valid = false;

        }





        if (document.getElementById('longDetails').value.length == 0)

        {

            validationMessage = validationMessage + '  - Long Details are missing\r\n';

            valid = false;

        }





        if (document.getElementById('shortDetails').value.length != 10)

        {

            validationMessage = validationMessage + '  - Short Details are missing.\r\n';

            valid = false;

        }




        if (document.getElementById('price').value.length == 0)

        {

            validationMessage = validationMessage + '  - Price is missing\r\n';

            valid = false;

        }

        if (document.getElementById('stock').value.length == 0)

        {

            validationMessage = validationMessage + '  - Stock is missing\r\n';

            valid = false;

        }





        if (valid == false)

        {

            alert(validationMessage);

        }



        return valid;

    }



</script> 
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.