Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jul 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Javascript : Loop passing

    i,

    Am developing a webform using PL/SQL.

    Am using javascript to do some form validation

    Sample

    if(a =="")
    {

    alert("Please enter the first name");
    return false;


    }


    else if(b =="")
    {


    alert("Please enter the last name");
    return false;


    }

    else if (y !="Test1")


    {
    if (y != "Test2")


    {


    if (y != "Test3")


    {
    alert("Enter the right text");
    return false;


    }
    }
    alert("am wrong outside");

    }


    else if(z =="")


    {


    alert("Please fill al the fields");
    return false;


    }

    it passes till alter("am wrong outside") and executes the procedure but doesnt goes to the last else part.

    I want it to go the last else part too.

    Please help.

  • #2
    Senior Coder Rowsdower!'s Avatar
    Join Date
    Oct 2008
    Location
    Some say it's everything.
    Posts
    2,027
    Thanks
    5
    Thanked 397 Times in 390 Posts
    Quote Originally Posted by user7272 View Post
    i,

    Am developing a webform using PL/SQL.

    Am using javascript to do some form validation

    Sample
    ...

    it passes till alter("am wrong outside") and executes the procedure but doesnt goes to the last else part.

    I want it to go the last else part too.

    Please help.
    That is the nature of the "else if" statement. If it finds one it skips the rest (which makes your "return false;" code superfluous in all but one of those places). For example, this code would function exactly the same as what you already have:
    Code:
    if(a ==""){
    	alert("Please enter the first name");
    }
    else if(b ==""){
    	alert("Please enter the last name");
    }
    else if (y !="Test1"){
    	if (y != "Test2"){ 
    		if (y != "Test3"){
    			alert("Enter the right text");
    			return false;
    		}
    	}
    	alert("am wrong outside");
    }
    else if(z ==""){
    	alert("Please fill al the fields");
    }
    If you wanted to run the last check, irrespective of any alert messages already received, you would want a simple "if" for the last one, rather than the "else if" that you have:
    Code:
    if(a ==""){
    	alert("Please enter the first name");
    }
    else if(b ==""){
    	alert("Please enter the last name");
    }
    else if (y !="Test1"){
    	if (y != "Test2"){ 
    		if (y != "Test3"){
    			alert("Enter the right text");
    			return false;
    		}
    	}
    	alert("am wrong outside");
    }
    if(z ==""){
    	alert("Please fill al the fields");
    }
    The object of opening the mind, as of opening the mouth, is to shut it again on something solid. –G.K. Chesterton
    See Mediocrity in its Infancy
    It's usually a good idea to start out with this at the VERY TOP of your CSS: * {border:0;margin:0;padding:0;}
    Seek and you shall find... basically:
    validate your markup | view your page cross-browser/cross-platform | free web tutorials | free hosting

  • #3
    New to the CF scene
    Join Date
    Jul 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks a lot dude.

    It worked!!!!!!.

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,918
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Validation of the form if(a ==""){ is barely worthy of the name, and virtually useless, as even a single space, an x or a ? will return false, that is pass the validation. Numeric values such as zip codes and phone numbers should be validated as such. This topic has been covered many times before in this forum.


    It is your responsibility to die() if necessary….. - PHP Manual


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •