By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,516 Members | 1,137 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,516 IT Pros & Developers. It's quick & easy.

About simple form validation

100+
P: 539
I am a newbie on JavaScript....

I would like to know about what's wrong in my code below:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2.     <head>
  3.         <title>Text Example</title>
  4.     </head>
  5.  
  6.     <body>
  7.         <script language="JavaScript">
  8.             <!--
  9.                 var home="http://127.0.1:8080/start.html";
  10.  
  11.                 function redirect(){
  12.                     document.location.href=var;
  13.                 }
  14.                 function checkInput(){
  15.                     if(document.textform.textfield.value==""){
  16.                         alert("Fields not filled");
  17.                         form.textfield.focus();
  18.                         form.textfield.select();
  19.                         return false;
  20.                     }else
  21.                         return true;
  22.                 }
  23.             -->
  24.         </script>
  25.  
  26.         <form name="textform" 
  27.               method="POST" 
  28.               action="JSPActions/textAction.jsp"
  29.               onsubmit="checkInput();">
  30.  
  31.             <h3>Text Example: User login</h3><br>
  32.             Username: <input type="text" name="textfield" size=10><br>
  33.             Password: <input type="password" name="password" size=10><br><br>
  34.             <input type="submit" value="Login">
  35.         </form>
  36.     </body>
  37. </html>
Actually, i have a subject that covers basic JSP, some html and accessing database and applets.....

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.....
Jun 28 '08 #1
Share this Question
Share on Google+
2 Replies


100+
P: 539
Ok, i have fixed it.....
Jun 28 '08 #2

acoder
Expert Mod 15k+
P: 16,027
That's good to hear. You should also post how you solved it for the benefit of others.
Jun 28 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.