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.
Page 2 of 9 FirstFirst 1234 ... LastLast
Results 16 to 30 of 124
  1. #16
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,021
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    *WHAT* validation?

    There is no validation there.

    It is just *FORCING* today's date to be shoved into the form field
    Code:
        <input type="text" size="30" id="date" name="date" />
    In what way does that have anything to do with validation???

    **********

    Or are you talking about this code:
    Code:
    		//Date Validation between 2000 and 2004
    	
    		var d = "01/01/2009";
    		var ds = d.split("/");
    		if ((ds[2] <2000) || (ds[2] > 2004))
    		 {
    		alert ("Please enter Years between 2000 and 2004");
    		}
    That code is utterly pointless. It is guaranteed to always give the alert, because you aren't testing anything except that string that you HARD CODED as "01/01/2009".

    You aren't making any sense.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  2. #17
    Regular Coder
    Join Date
    Apr 2013
    Posts
    112
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thats right, suppose to give us todays date lol

    I'm talking about this , doesn't run even though it's correct..
    Code:
    		
    		// If AGREE isn't ticked no alert, if it's left blank an alert dialog will appear	
    		if (document.getElementById('agreed').checked == false) 
     		{
    
      		alert ("You didn't agree to the terms");
    
      		return false;
    
    		 } 
     		else
      		{
    
      		return true;
    
    		 }
    
    			
    	
    }

  3. #18
    Regular Coder
    Join Date
    Apr 2013
    Posts
    112
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Oh and this is incorrect, when i type a date say 12/12/2001 i still get a alert?

    Code:
    var d = "01/01/2009";
    		var ds = d.split("/");
    		if ((ds[2] <2000) || (ds[2] > 2004))
    		 {
    		alert ("Please enter Years between 2000 and 2004");
    		}

  4. #19
    Regular Coder
    Join Date
    Apr 2013
    Posts
    112
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Forgot to state the Date code how would i do it like all my other validating using Regex?

  5. #20
    Regular Coder
    Join Date
    Apr 2013
    Posts
    112
    Thanks
    1
    Thanked 0 Times in 0 Posts
    All i need to do is Debug my code the way i sent you Old Pendant , and just re do the date validation between 2001 and 2004 then im set

  6. #21
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,021
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    Quote Originally Posted by Johnny87auxsm View Post
    Oh and this is incorrect, when i type a date say 12/12/2001 i still get a alert?

    Code:
    var d = "01/01/2009";
    		var ds = d.split("/");
    		if ((ds[2] <2000) || (ds[2] > 2004))
    		 {
    		alert ("Please enter Years between 2000 and 2004");
    		}
    One more time: NO MATTER WHAT anybody puts into any <form> field, *THAT CODE* is ONLY going to test the string you are using there: "01/01/2009".

    So it is *ALWAYS* going to give the alert message.

    IT IS NOT TESTING ANYTHING AT ALL FROM THE <FORM>.

    And no, I'm not going to fix that for you, since you figured out how to test other form fields, apparently.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  7. #22
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,021
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    Quote Originally Posted by Johnny87auxsm View Post
    Thats right, suppose to give us todays date lol

    I'm talking about this , doesn't run even though it's correct..
    Code:
    		
    		// If AGREE isn't ticked no alert, if it's left blank an alert dialog will appear	
    		if (document.getElementById('agreed').checked == false) 
     		{
    
      		alert ("You didn't agree to the terms");
    
      		return false;
    
    		 } 
     		else
      		{
    
      		return true;
    
    		 }
    
    			
    	
    }
    I don't see anything wrong with that code.

    If it's not working, then it's probably some error before that point.

    Time to use the debugger.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  8. #23
    Regular Coder
    Join Date
    Apr 2013
    Posts
    112
    Thanks
    1
    Thanked 0 Times in 0 Posts
    That's what im saying, it's 100% correct but WHY isn't it working !???
    And i got the regex for the date between 2001 and 2004 but isn't working either? I put an alert as its required for the assignment not the value to be displayed in the textbox..

    Code:
    		 var dt = formtag.dob.value;
        var dtre = /^(0?[1-9]|[12][0-9]|3[01])[\/\-](0?[1-9]|1[012])[\/\-]\d{4}$/;
        if ( ! dtre.test(dt) )
        {
            formtag.dob.value = "invalid";
            return false;
        }
        var parts = dt.split("/");
        var check = new Date(parts[2],parts[0]-1,parts[1]);
        if (    check.getMonth() != Number(parts[0])
             || check.getYear() < 2000 || check.getYear() > 2004 )
        {
            alert ("invalid dob");
            return false;
        }

  9. #24
    Regular Coder
    Join Date
    Apr 2013
    Posts
    112
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Your giving me awesome advice but debugging the code isn't helping, scrap the date validation for now .. I just want to get all my javascript working i sent you.. Leave as is and it still don't work ??

  10. #25
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,021
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    Code:
        var check = new Date(parts[2],parts[0]-1,parts[1]);
        if (    check.getMonth() != Number(parts[0])
    *THINK* about that for a minute.

    You supply a month that is parts[0]-1

    And then you TEST for the month being parts[0]

    Does that really make a lick of sense?

    Anyway, night-night time again.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  11. #26
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,387
    Thanks
    11
    Thanked 565 Times in 558 Posts
    The most prominent error in your code (multiple occurrences):

    document.getElementById() will give you the element, not its content. The method .toString() will convert the element type to a string like "[object HTMLDivElement]"
    Code:
    var fNameString = document.getElementById('fname');
    fNameString = fNameString.toString();

  12. #27
    Regular Coder
    Join Date
    Apr 2013
    Posts
    112
    Thanks
    1
    Thanked 0 Times in 0 Posts
    is that really an error? That shouldn't stop one of my validations to stop working ? If u download the attachment you will see once u hit submit all the validations work up until the male/female alert, this bit of code doesn't display an alert ??

    Code:
    	// If AGREE isn't ticked no alert, if it's left blank an alert dialog will appear	
    		if (document.getElementById('agreed').checked == false) 
     		{
    
      		alert ("You didn't agree to the terms");
    
      		return false;
    
    		 } 
     		else
      		{
    
      		return true;
    
    		 }

  13. #28
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,893
    Thanks
    202
    Thanked 2,528 Times in 2,506 Posts
    Quote Originally Posted by Johnny87auxsm View Post
    is that really an error? That shouldn't stop one of my validations to stop working ? If u download the attachment you will see once u hit submit all the validations work up until the male/female alert, this bit of code doesn't display an alert ??

    Code:
    	// If AGREE isn't ticked no alert, if it's left blank an alert dialog will appear	
    		if (document.getElementById('agreed').checked == false) 
     		{
    
      		alert ("You didn't agree to the terms");
    
      		return false;
    
    		 } 
     		else
      		{
    
      		return true;
    
    		 }
    Thre is nothing wrong with your code. The error must be elsewhere. Are you using your error console? That is what it is there for.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  14. #29
    Regular Coder
    Join Date
    Apr 2013
    Posts
    112
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Phillip sure am mate 100%, im using the developer tools in chrome, displays no ERRORS ? Can you check and see if it also displays no errors on ur side?

  15. #30
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,387
    Thanks
    11
    Thanked 565 Times in 558 Posts
    is that really an error? That shouldn't stop one of my validations to stop working ?
    This is not a syntax error but rather a logical error. You can still compare the string "[object HTMLDivElement]" with other strings or check if its length is > 35 etc. ... but this is certainly NOT what you wanted to achieve, is it?


 
Page 2 of 9 FirstFirst 1234 ... LastLast

Posting Permissions

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