call function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ammyra91
    New Member
    • Nov 2011
    • 18

    call function

    hi evryone.....i would like to ask your favour regarding on my php code.....this is my code....

    Code:
    <html>
    <head>
    <title>
    </title>
    <script type="text/javascript">
    function validation()
    {
    	var valid=true;
        if(document.form2.icnumber.value=="")
        {
        	alert(" Please fill in the ' Identification Card Number ' textbox. ");
            document.form2.icnumber.focus();
            valid=false;
    	}
        
        if(document.form2.name.value=="")
        {
        	alert(" Please fill in the ' Name ' textbox. ");
            document.form2.name.focus();
            valid=false;
    	}
    	
    	if(document.form2.position.value=="")
        {
        	alert(" Please fill in the ' Position ' textbox. ");
            document.form2.position.focus();
            valid=false;
    	}
        
        if(document.form2.department.value=="")
        {
        	alert(" Please fill in the ' Department ' textbox. ");
            document.form2.department.focus();
            valid=false;
    	}
    
    	/*if(document.form2.email.value=="")
        {
        	alert(" Please fill in the ' Email ' textbox. ");
        	document.form2.email.focus();
        	valid=false;
    	}*/
        
        if(document.form2.phoneno.value=="")
        {
        	alert(" Please fill in the ' Phone Number ' box. ");
            document.form2.phoneno.focus();
            valid=false;
    	}
    	
    	 if(document.form2.username.value=="")
        {
        	alert(" Please fill in the ' User Name ' textbox. ");
            document.form2.username.focus();
            valid=false;
    	}
        
        if(document.form2.password.value=="")
        {
        	alert(" Please fill in the ' Password ' box. ");
            document.form2.password.focus();
            valid=false;
    	}
        return valid;
    }
    
    function echeck(str) {
    
    		var at="@"
    		var dot="."
    		var lat=str.indexOf(at)
    		var lstr=str.length
    		var ldot=str.indexOf(dot)
    		if (str.indexOf(at)==-1){
    		   alert("Invalid E-mail ID")
    		   return false
    		}
    
    		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
    		   alert("Invalid E-mail ID")
    		   return false
    		}
    
    		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
    		    alert("Invalid E-mail ID")
    		    return false
    		}
    
    		 if (str.indexOf(at,(lat+1))!=-1){
    		    alert("Invalid E-mail ID")
    		    return false
    		 }
    
    		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
    		    alert("Invalid E-mail ID")
    		    return false
    		 }
    
    		 if (str.indexOf(dot,(lat+2))==-1){
    		    alert("Invalid E-mail ID")
    		    return false
    		 }
    		
    		 if (str.indexOf(" ")!=-1){
    		    alert("Invalid E-mail ID")
    		    return false
    		 }
    
     		 return true					
    	}
    
    function ValidateForm()
    {
    	var emailID=document.form2.email
    	
    	if ((emailID.value==null)||(emailID.value==""))
    	{
    		alert("Please Enter your Email ID")
    		emailID.focus()
    		return false
    	}
    	
    	if (echeck(emailID.value)==false){
    		emailID.value=""
    		emailID.focus()
    		return false
    	}
    	return true
    }
     
    function valForm()
    {
    
    	validateForm();
    	validation();
     
    }
    
    </script></head>
    <body>
    <form name="form2" method="post" action="register0.php" onSubmit="return valForm();">
    
    <table border=3>
    <tbody>
    <tr>
    <td style="text-align: center;">
    <p><strong>Registration Form</strong></p>
    <table border="0" cellspacing="1" cellpadding="3">
    <tbody>
    
    <tr align="left" bgcolor="#FFFFFF">
    <td><span style="font-family: Arial; font-size: small;">Identification Card Number</span></td>
    <td><span style="font-family: Arial; font-size: small;"> : </span></td>
    <td><span style="font-family: Arial; font-size: small;"><input type="text" name="icnumber"></span></td>
    </tr>
    
    <tr align="left" bgcolor="#FFFFFF">
    <td><span style="font-family: Arial; font-size: small;">Name</span></td>
    <td><span style="font-family: Arial; font-size: small;"> : </span></td>
    <td><span style="font-family: Arial; font-size: small;"><input type="text" name="name"></span></td>
    </tr>
    
    <tr align="left" bgcolor="#FFFFFF">
    <td><span style="font-family: Arial; font-size: small;">Position</span></td>
    <td><span style="font-family: Arial; font-size: small;"> : </span></td>
    <td><span style="font-family: Arial; font-size: small;"><input type="text" name="position"></span></td>
    </tr>
    
    <tr align="left" bgcolor="#FFFFFF">
    <td><span style="font-family: Arial; font-size: small;">Department</span></td>
    <td><span style="font-family: Arial; font-size: small;"> : </span></td>
    <td><span style="font-family: Arial; font-size: small;"><input type="text" name="department"></span></td>
    </tr>
    
    <tr align="left" bgcolor="#FFFFFF">
    <td><span style="font-family: Arial; font-size: small;">Email</span></td>
    <td><span style="font-family: Arial; font-size: small;"> : </span></td>
    <td><span style="font-family: Arial; font-size: small;"><input type="text" name="email"></span></td>
    </tr>
    
    <tr align="left" bgcolor="#FFFFFF">
    <td><span style="font-family: Arial; font-size: small;">Phone Number</span></td>
    <td><span style="font-family: Arial; font-size: small;"> : </span></td>
    <td><span style="font-family: Arial; font-size: small;"><input type="text" name="phoneno"></span></td>
    </tr>
    
    <tr align="left" bgcolor="#FFFFFF">
    <td><span style="font-family: Arial; font-size: small;">User Name</span></td>
    <td><span style="font-family: Arial; font-size: small;"> : </span></td>
    <td><span style="font-family: Arial; font-size: small;"><input type="text" name="username"></span></td>
    </tr>
    
    <tr align="left" bgcolor="#FFFFFF">
    <td><span style="font-family: Arial; font-size: small;">Password</span></td>
    <td><span style="font-family: Arial; font-size: small;"> : </span></td>
    <td><span style="font-family: Arial; font-size: small;"><input type="password" name="password"></span></td>
    </tr>
    
    <tr align="left" bgcolor="#FFFFFF">
    <td colspan=3 align=center><span style="font-family: Arial; font-size: small;"><input type="submit" name="submit" value="Send Form"><input type="reset" name="reset" value="Empty Form"></span></td>
    </tr>
    
    </tbody>
    </table>
    </td>
    </tr>
    </tbody>
    </table>
    </form>
    </body>
    </html>

    I would like to use function valForm when clicking on submit button....unfor tunately, the validation function and the validate form is not working.....som ebody plz help me.....
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    What do you mean by not working.

    Comment

    • ammyra91
      New Member
      • Nov 2011
      • 18

      #3
      rabbit:

      the 1st case is : (in function validation)
      for example,i didn't enter any information in one of the text box.when i click submit, it should display an alert box saying that, "Please fill in 'Name' textbox" for example...but, instead of that, it just go to new window and display "Data have been save" or "Record existed". Thus, there will be an empty space in a database.


      the 2nd case is: (in function validateForm)
      it should display an alert box when we entered wrong email....it act as an email validation. as we see, in function validation, i had already put the email validation as a comment so that the system will not be malfunction. before this, i had tried the function validateForm in another page, and it is working.so i would like to combine it with the other textbox validation that is function validation.

      3rd cases : (function valForm)
      this function should be able to validate all textbox in this register.php page(the code for register.php page is as above code that i had post in the question)which including the email validation and name,department etc.unluckly it is not working as i expected. so, i would like to ask your opinion on what should i do so that both function is working.

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        1) Your onsubmit called function never returns true or false depending on the return values of the functions that it calls. That's why it always submits. Also, you never see the alerts because ValidateForm fails to run correctly.

        2) ValidateForm and echeck is not valid javascript. I suspect in the other page you were using vbscript. They are not the same. You need to port those functions to javascript.

        3) This is directly related to the previous issues.

        Comment

        Working...