I would like to know about what's wrong in my code below:
Expand|Select|Wrap|Line Numbers
- <html>
- <head>
- <title>Text Example</title>
- </head>
- <body>
- <script language="JavaScript">
- <!--
- var home="http://127.0.1:8080/start.html";
- function redirect(){
- document.location.href=var;
- }
- function checkInput(){
- if(document.textform.textfield.value==""){
- alert("Fields not filled");
- form.textfield.focus();
- form.textfield.select();
- return false;
- }else
- return true;
- }
- -->
- </script>
- <form name="textform"
- method="POST"
- action="JSPActions/textAction.jsp"
- onsubmit="checkInput();">
- <h3>Text Example: User login</h3><br>
- Username: <input type="text" name="textfield" size=10><br>
- Password: <input type="password" name="password" size=10><br><br>
- <input type="submit" value="Login">
- </form>
- </body>
- </html>
So, i am attempting to do it with javascript(bad input).....
On the laboratory, we didn't started yet to trap any bad/no input on the textfield
So, just to increase my appetite on web programming, i would like to validate the form using javascript( as java covers all type of Exceptions )
And i get stuck on the code above....
What's wrong with my code? It didn't invoke the checkInput method.....
Any advice? or URL that could explain it to me the effective way to validate a form?
Im looking forward to your replies experts.....