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 5 of 9 FirstFirst ... 34567 ... LastLast
Results 61 to 75 of 124
  1. #61
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,438
    Thanks
    75
    Thanked 4,372 Times in 4,337 Posts
    Answered in separate thread.
    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. #62
    Regular Coder
    Join Date
    Apr 2013
    Posts
    112
    Thanks
    1
    Thanked 0 Times in 0 Posts
    old pedant i have this in my form, how do i add validateForm next to validateSectionz(this) ??
    Code:
    id="formtag"  onsubmit="return validateSectionz(this)">
    but i've copied this into my HTML using the <script></script> tags

    Code:
      		
     <script type="text/javascript">
    function validateDob( )
    {
    	var dateStr = document.getElementById('dob').value;
    	var dateAry = dateStr.split('/');
    	if (3 !== dateAry.length )
            { 
                return false; // date is invalid 
            }
     	var m = Number(dateAry[0]) - 1;
     	var d = Number(dateAry[1]);
     	var y = Number(dateAry[2]);
     	var dt = new Date(y, m, d);
     	if (d !== dt.getDate() || m !== dt.getMonth() || y !== dt.getFullYear()) 
            {
                return false; // month, day or year outside of the valid range
            }
            if  (y < 2001 || y > 2004)
            {
                return false; // added line to check between 2001 and 2004        
            }
    	return true;
    }
    
    function validateForm( )
    {
        if ( ! validateDob( ) ) 
        {
            alert("Invalid DOB");
            return false;
        }
        alert("Okay, form will submit");
        return true;
    }
    </script>

  3. #63
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,438
    Thanks
    75
    Thanked 4,372 Times in 4,337 Posts
    Quote Originally Posted by Johnny87auxsm View Post
    old pedant i have this in my form, how do i add validateForm next to validateSectionz(this) ??
    Code:
    id="formtag"  onsubmit="return validateSectionz(this)">
    YOu don't.

    You just copy *THIS* code right into your validateSectionz code:
    Code:
      		
        if ( ! validateDob( ) ) 
        {
            alert("Invalid DOB");
            return false;
        }
    along with the validateDob() function, of course.
    Last edited by Old Pedant; 05-07-2013 at 06:19 AM.
    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.

  4. #64
    Regular Coder
    Join Date
    Apr 2013
    Posts
    112
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I see dude i see, i've copied this below straight into my validateSectionz javascript file correct?

    Code:
    		 function validateDob( )
    {
    	var dateStr = document.getElementById('dob').value;
    	var dateAry = dateStr.split('/');
    	if (3 !== dateAry.length )
            { 
                return false; // date is invalid 
            }
     	var m = Number(dateAry[0]) - 1;
     	var d = Number(dateAry[1]);
     	var y = Number(dateAry[2]);
     	var dt = new Date(y, m, d);
     	if (d !== dt.getDate() || m !== dt.getMonth() || y !== dt.getFullYear()) 
            {
                return false; // month, day or year outside of the valid range
            }
            if  (y < 2001 || y > 2004)
            {
                return false; // added line to check between 2001 and 2004        
            }
    	return true;
    }
    
    function validateForm( )
    {
        if ( ! validateDob( ) ) 
        {
            alert("Invalid DOB");
            return false;
        }
        alert("Okay, form will submit");
        return true;
    }

  5. #65
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,438
    Thanks
    75
    Thanked 4,372 Times in 4,337 Posts
    No. Wrong.

    Read my answer a few dozen times until you understand it.

    I have gone back and highlighted the part you need to read in red.
    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.

  6. #66
    Regular Coder
    Join Date
    Apr 2013
    Posts
    112
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Old Pedant View Post
    No. Wrong.

    Read my answer a few dozen times until you understand it.

    I have gone back and highlighted the part you need to read in red.
    I've read it 5 times now i dont undertstand what your saying, I copied the code u tagged into my validateSectionz javascript file, along with the function ?

  7. #67
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,438
    Thanks
    75
    Thanked 4,372 Times in 4,337 Posts
    *SIGH*.

    I had no idea you even *HAVE* a "validateSectionz.js" file.

    The last I saw, you were using
    Code:
    <script src="javascript.js" type="text/javascript"> </script>
    Okay, I'll try to make it more explicit:
    You just copy *THIS* code right into your validateSectionz( ) function's code:
    Code:
        if ( ! validateDob( ) ) 
        {
            alert("Invalid DOB");
            return false;
        }
    along with the validateDob() function, of course.
    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. #68
    Regular Coder
    Join Date
    Apr 2013
    Posts
    112
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Old Pedant View Post
    *SIGH*.

    I had no idea you even *HAVE* a "validateSectionz.js" file.

    The last I saw, you were using
    Code:
    <script src="javascript.js" type="text/javascript"> </script>
    Okay, I'll try to make it more explicit:
    I'm doing exactly what u told me to, copy the validateDOB function along with the little bit of code u quoted into my validateSection function correct?

  9. #69
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,438
    Thanks
    75
    Thanked 4,372 Times in 4,337 Posts
    I give up.

    SHOW me what you did.

    Better yet, post a live URL, if you can. Failing that, zip up the code again, *THIS* time with the JS file.
    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.

  10. #70
    Regular Coder
    Join Date
    Apr 2013
    Posts
    112
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Sorry man i'm not as experienced as you :P
    Attached Files Attached Files

  11. #71
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,438
    Thanks
    75
    Thanked 4,372 Times in 4,337 Posts
    I can not believe that you are unable to follow VERY SIMPLE instructions.

    *WHERE* in *ANYTHING* I wrote did I tell you to copy the ENTIRE validateForm function into your validateSectionz code?

    LOOK ONE MORE TIME AT THE INSTRUCTIONS I GAVE YOU:
    You just copy *THIS* code right into your validateSectionz( ) function's code:
    Code:
        if ( ! validateDob( ) ) 
        {
            alert("Invalid DOB");
            return false;
        }
    along with the validateDob() function, of course.
    JUST THAT CODE. NO MORE. NOT THE COMPLETE validateForm function.

    But you have made utter hash out of the other code, too.

    You are returning booValid which is no longer even DEFINED in your code.

    And you have removed all the validation you once had for first name, etc.

    WHY!???!!!???

    I can't believe you have spent this much time on this project and you aren't even as far along now as you were DAYS ago.

    It really seems pointless to give this to you, but here it is:
    Code:
    function validateSectionz()
    {
        // you can have validations for other fields here...
    
        if ( ! validateDob( ) ) 
        {
            alert("Invalid DOB");
            return false;
        }
     
        // or you can have other field validations here...
    
        // or you can have them both places.
    
        // if a validation fails, you need to return false
    
        // only if all validation succeeds do you get to this line:
        return true;
    }
    
    function validateDob( )
    {
    	var dateStr = document.getElementById('dob').value;
    	var dateAry = dateStr.split('/');
    	if (3 !== dateAry.length )
            { 
                return false; // date is invalid 
            }
     	var m = Number(dateAry[0]) - 1;
     	var d = Number(dateAry[1]);
     	var y = Number(dateAry[2]);
     	var dt = new Date(y, m, d);
     	if (d !== dt.getDate() || m !== dt.getMonth() || y !== dt.getFullYear()) 
            {
                return false; // month, day or year outside of the valid range
            }
            if  (y < 2001 || y > 2004)
            {
                return false; // added line to check between 2001 and 2004        
            }
    	return true;
    }
    I suspect that you won't understand what I mean by the lines in blue there. But I don't know what else to say.
    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.

  12. #72
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,438
    Thanks
    75
    Thanked 4,372 Times in 4,337 Posts
    And I probably shouldn't do this, either. But here's a fix for those two validations you commented out. Much cleaner and neater.
    Code:
    function validateSectionz()
    {
    
        var num8re = /^\d{8}$/;
      
        if ( document.getElementById("US").checked )
        {
            var sn = document.getElementById("SN");
            if ( ! num8re.test(sn) ) 
            {
                 alert("Please enter an 8 digit number");
                 sn.focus();
                 return false;
            }
        }
        if ( document.getElementById("UA").checked )
        {
            var stn = document.getElementById("STN");
            if ( ! num8re.test(stn) ) 
            {
                 alert("Please enter an 8 digit number");
                 stn.focus();
                 return false;
            }
        }
    
        // and more validation
    
        if ( ! validateDob( ) ) 
        {
            alert("Invalid DOB");
            return false;
        }
     
        // and more validation
        
        return true;
    }
    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.

  13. #73
    Regular Coder
    Join Date
    Apr 2013
    Posts
    112
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Old Pedant View Post
    I can not believe that you are unable to follow VERY SIMPLE instructions.

    *WHERE* in *ANYTHING* I wrote did I tell you to copy the ENTIRE validateForm function into your validateSectionz code?

    LOOK ONE MORE TIME AT THE INSTRUCTIONS I GAVE YOU:

    JUST THAT CODE. NO MORE. NOT THE COMPLETE validateForm function.

    But you have made utter hash out of the other code, too.

    You are returning booValid which is no longer even DEFINED in your code.

    And you have removed all the validation you once had for first name, etc.

    WHY!???!!!???

    I can't believe you have spent this much time on this project and you aren't even as far along now as you were DAYS ago.

    It really seems pointless to give this to you, but here it is:
    Code:
    function validateSectionz()
    {
        // you can have validations for other fields here...
    
        if ( ! validateDob( ) ) 
        {
            alert("Invalid DOB");
            return false;
        }
     
        // or you can have other field validations here...
    
        // or you can have them both places.
    
        // if a validation fails, you need to return false
    
        // only if all validation succeeds do you get to this line:
        return true;
    }
    
    function validateDob( )
    {
    	var dateStr = document.getElementById('dob').value;
    	var dateAry = dateStr.split('/');
    	if (3 !== dateAry.length )
            { 
                return false; // date is invalid 
            }
     	var m = Number(dateAry[0]) - 1;
     	var d = Number(dateAry[1]);
     	var y = Number(dateAry[2]);
     	var dt = new Date(y, m, d);
     	if (d !== dt.getDate() || m !== dt.getMonth() || y !== dt.getFullYear()) 
            {
                return false; // month, day or year outside of the valid range
            }
            if  (y < 2001 || y > 2004)
            {
                return false; // added line to check between 2001 and 2004        
            }
    	return true;
    }
    I suspect that you won't understand what I mean by the lines in blue there. But I don't know what else to say.
    I've done alot of validations just didnt want to attach them as i know people will be watching this thread...

  14. #74
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,438
    Thanks
    75
    Thanked 4,372 Times in 4,337 Posts
    Well anybody from your class who is watching this thread, including your instructor, will know by now that you haven't the foggiest idea what you are doing. And about the worst thing they could do would be to copy your validation code. Any of it.

    Even the stuff you said was working was maybe 3 times more complex than it needed to be and had errors and holes one could drive a semi-truck through.

    The only thing you are accomplishing by not showing your code is making it harder for me (and others, if anybody else hasn't given up by now) to fix it for you.

    The best thing you could do at this point would probably be to scrap all the code and start over. Hopefully having learned something better by now.

    Here's one hint: There's almost surely NO REASON AT ALL for you to be using document.getElementById( ) in any of your validation code.
    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.

  15. #75
    Regular Coder
    Join Date
    Apr 2013
    Posts
    112
    Thanks
    1
    Thanked 0 Times in 0 Posts
    1 STEP so close 1 step so far >_< , everything is working just the function you helped with which is the one i WANT to work isn't lol , i attached it so u can see it with all my validations, i copied my validations where u commented the first blue lines above ^

    Attached -
    Attached Files Attached Files


 
Page 5 of 9 FirstFirst ... 34567 ... 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
  •