Validation problem

Discussion in 'JavaScript' started by MSK7, Feb 26, 2009.

  1. #1
    In my form validation is applied for informing Invalid data entered in the field before submit the form instantly at the time of mistake.

    After throwing the correct instant alert message of mistake ,

    the Invalid data entered by user get selected but does not Erased

    and invalid data remain selected after this.

    please suggest me

    what should done so that the invalid data entered should be Erased completely after giving Error alert message of "Invalide data" .

    & the text field get empty for entering new valid data in it.

    small code of my form is shown below:-

    
    
    <html>
    <head>
    
    <script type="text/javascript">
    
    function validate_required(form2)
    {	  	  
          if (form2.name.value=="")
           {	   
           alert("Please enter the Full Name");	        
           document.form2.name.focus();
           return false;
           }	  
       return true;
    }
    
    
     function checkName()
     { 
    	    	      	    
         if (!isNaN(document.getElementById('name').value)) 
          {	   
           alert("Invalid numeric value entered! Please enter the Valid Name");   
           document.form2.name.focus();
           return false;
           }	
     return true;
    }
    
    </script>
    </head>
    
    
    <body>
    
    <form name="form2"  id="form2"  onsubmit="return validate_required(this)"   action="infosubmit2.php"   method="post" >
    
     Name :  <input type="text"   name="name"   id="name"       onkeyup="checkName()"     size="40"   /> 
    
    </body>
    </html>
    
    
    Code (markup):

    Thanks & Regards.
     
    MSK7, Feb 26, 2009 IP
  2. lp1051

    lp1051 Well-Known Member

    Messages:
    163
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    108
    #2
    Hi MSK7,

    just add this before calling the focus() in both functions. That tells that the value of the form field called 'name' should be set to '' (empty string).

    document.form2.name.value = '';
     
    lp1051, Feb 26, 2009 IP
  3. MSK7

    MSK7 Member

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #3
    Hello sir,

    Thanks for your precious Suggession for this problem.

    Your guidance solved my problem .

    Hope to get your precious suggessions & guidance in future also.


    Thanks & Regards.
     
    MSK7, Feb 27, 2009 IP