JSP page's form not validating data with my Javascript -


issue

the problem is, jsp sends form servlet, without validating javascript.


javascript

function testinputtext() {     var x, text;      x = document.getelementbyid("inputtext").value;      if (typeof x != "string") {         text = "invalid input js";         document.getelementbyid("scripterror").innerhtml = text;         return false;     } else if(x ==""){         text = "no input found js";         document.getelementbyid("scripterror").innerhtml = text;         return false;     } else {text = "valid js";         document.getelementbyid("scripterror").innerhtml = text;         return true;     }  } 

formular.jsp

<!doctype html> <html>     <head>         <script src="javascripts/mailvalidation.js"></script>         <title>formular</title>     </head>     <body>         <form name="formular" onsubmit="return testinputtext()" method="post"  action="/formsend"  >         <fieldset>             <legend class="legendpersonal">personal information</legend>             <br>             <p class="formdescription"> fname: </p>             <p class="falseinput"> ${fnamef}</p>             <p id="sripterror"></p>             <input type="text" id="inputtext" name="fname" value=${fname} >             <br>             <input type="submit" value="send" >         </form>     </body> </html> 

my file formular.jsp in resource directory called "web". javascript file in subdirectory called "javascripts" under "web" well.

denis trying access scripterrorwhereas have not added id jsp page named scripts.i think mistake add sripterror.

updated jsp code :

<!doctype html> <html> <head>     <script src="javascripts/mailvalidation.js"></script>     <title>formular</title> </head> <body>     <form name="formular" onsubmit="return testinputtext()" method="post"  action="/formsend"  >     <fieldset>         <legend class="legendpersonal">personal information</legend>         <br>         <p class="formdescription"> fname: </p>         <p class="falseinput"> ${fnamef}</p>         <p id="scripterror"></p>         <input type="text" id="inputtext" name="fname" value=${fname} >         <br>         <input type="submit" value="send" >     </form>     </body>   </html> 

js :

function testinputtext() { var x, text;  x = document.getelementbyid("inputtext").value;  if (typeof x != "string") {     text = "invalid input js";     document.getelementbyid("scripterror").innerhtml = text;     return false; } else if(x ==""){     text = "no input found js";     document.getelementbyid("scripterror").innerhtml = text;     return false; } else {text = "valid js";     document.getelementbyid("scripterror").innerhtml = text;     return true; }  } 

good luck , let me know other help.


Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -