To validate from jsp to javascript

Asked 2 years ago, Updated 2 years ago, 102 views

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
      <style>
         ul {
             list-style:none;
         }
         li {
             margin:10px;
         }
         li label {
             width:120px;
            float:left;
            text-align:right;
            padding-right:8px;
         }
         input[type="submit"] {
             text-align:center;
             width:100%;
             height:30px;
             margin-top:15px;
         }
         </style>

 <link href="StyleSheet1.css" type="text/css" rel="stylesheet" />
</head>
<body>
<%@include file="myNav.html" %>
<%@include file="myNav1.html" %>

<form name="signupform" action="singUp_ok.jsp" method="post">
            <fieldset>
                <legend>Login Information</legend>
                <ul>
                    <li>
                    <label for="user-id">ID </label>
                         <input type="text" name="user-id">
                    </li>
                    <li>
                        <label for="pwd1"> Password </label>
                        <input type="password" name="pwd1">
                    </li>
                    <li>
                        <label for="pwd2"> Confirm Password </label>
                        <input type="password" name="pwd2">             
                    </li>
                </ul>
                    <input type="button" value="join" onclick="signUpCheck()">
            </fieldset>

            </form>


</body>
</html>

<script language="javascript">

function singUpCheck() {
    var form = document.signupform;

    if(!form.user-id.value) {
        alert("Please enter your ID");
        form.user-id.focus();
        return;
    }

    form.submit();


}

</script>

Above is my jsp code.

I want to validate it with JavaScript, but there is no response even if I press the subscribe button.

Please check if the code for validation is correct.

Where do developers usually put their style sheets when working? Do you put it in the jsp?

jsp javascript

2022-09-22 21:09

1 Answers

<script>
function signUpCheck() {
    var form = document.signupform;
    if(!form['user-id'].value) {
        alert("Please enter your ID");
        form['user-id'].focus();
        return;
    }
    alert('success');
}
</script>

Change it like the sauce above.


2022-09-22 21:09

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.