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 11 of 11
  1. #1
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,376
    Thanks
    263
    Thanked 32 Times in 31 Posts

    function not repeat validating

    Hi i wrote a function to validate my input but what is happening is that it kicks me out and alerts me to the first issue, but then once the clubname is done the
    other checks do not execute and it writes to the db without validating the remaining inputs.

    here is the function

    Code:
    <script type="text/javascript"> 
    
    function validate_thisinfo()
    {
    
                /* clubname */
    
               if (document.clubform.clubname.value.length < 1)
               {
                 alert("Club Name is a required field.");
                 document.clubform.clubname.focus();
                 return(false);
               }
    
               if (document.clubform.clubname.value.length > 50)
               {
                 alert("Club Name is limited to 50 char.");
                 document.clubform.clubname.focus();
                 return(false);
               }
    
                /* clubcity */
               if (document.clubform.clubcity.value.length < 1)
               {
                 alert("Club City is a required field.");
                 document.clubform.clubcity.focus();
                 return(false);
               }
    
               if (document.clubform.clubcity.value.length > 50)
               {
                 alert("Club City is limited to 50 char.");
                 document.clubform.clubcity.focus();
                 return(false);
               }
    
    return(true);
    }//close function validate_thisinfo
    
    </script>
    So what happens is that it alerts me when clubname is blank but when i input club name and leave city blank it should alert me again when i
    click submit but it does not it just writes to the db without validating the city or any other info.

    It should return false unless it passes all tests then returns true.


    Im not sure why it is not re exicuting the function every time i click submit.

    Here is the call to the function

    Code:
    <input type="submit" name="Submit" value="Submit" class="button" onClick="return validate_thisinfo()" />
    Thanks im not sure why its not working, any help would be appreciated.
    Last edited by durangod; 09-10-2012 at 10:56 PM.

  • #2
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    Change return(false) to return false;

    Ditto for true.
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #3
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,376
    Thanks
    263
    Thanked 32 Times in 31 Posts
    Changed and still doing same thing, catches the first if statment but then once that is fixed it does not execute or revalidate on click and writes to db

    and all my other scripts that work use return (value); not return value; so im not sure what i missed here
    Last edited by durangod; 09-10-2012 at 05:09 PM.

  • #4
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    For form validation, you aren't returning a value. return false; prevents the form from being submit. Or, at least it's supposed to.

    Have you checked the error console to see if any JavaScript error messages are being presented? If the JavaScript is breaking, this would allow the form to submit.
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #5
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,376
    Thanks
    263
    Thanked 32 Times in 31 Posts
    no errors i did validate with php because i want to do both javascript popups and also errorpage so the php is working but i still cant get the javascript to revalidate, pretty strange.

    Im still digging, i copied a function from another script that works and same thing. Really wierd stuff.

    I will keep you posted, if you have any ideas please share, maybe you have something i can post in there to test if javascript is working right.

  • #6
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,376
    Thanks
    263
    Thanked 32 Times in 31 Posts
    I also just tried this and nothing, no reaction at all when i left the field. And yes did change the function hame to validateinfo i was easier to remember lol

    Code:
    <input type="text" name="clubcity" id="clubcity" maxlength="50" value="" onblur="return validateinfo();" />
    Update: i did a test where i changed the onClick to another function that just checks one if statment at a time, i put one statement in there. And it worked, so the issue must be with having multiple statments...


    Update 2 i think i may be onto something here, i just added another if to that function and they both worked, got two popups so now i will try adding one at a time to that function and see what happens. really really strange stuff i swear never a dull moment...
    Last edited by durangod; 09-10-2012 at 09:24 PM.

  • #7
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,376
    Thanks
    263
    Thanked 32 Times in 31 Posts
    I got it working, i had mispelled one of the vars in the function grrrrrrr im so embarrassed. Also i guess if all passes it defaults to return true because i removed the return true from the function and if all data is correct it it submits.

    is that correct, does it default to true unless it is changed to false?

  • #8
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    I am out of ideas. The brackets are opened/closed properly. The code looks good. I'm stumped as to why the error console is not showing any error messages. Are you using IE or FF?
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • Users who have thanked WolfShade for this post:

    durangod (09-10-2012)

  • #9
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,907
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Quote Originally Posted by durangod View Post
    is that correct, does it default to true unless it is changed to false?

    Yes.

    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.

  • Users who have thanked Philip M for this post:

    durangod (09-10-2012)

  • #10
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    You should attach an "onsubmit" attribute to the form rather than "onclick" to the submit button.

    Code:
    <form id="frmContact" action="" method="post" onsubmit="return validateinfo(this);">
    
    function validateinfo(frm) {
        // return false to prevent form submission..
        // otherwise, do nothing and the form will submit.
    }
    You can still use "onblur", etc., to validate data as they complete the form but returning true/false from such events will have no affect on the form submission. I would, therefore, not use the same function for these different events.
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • Users who have thanked AndrewGSW for this post:

    durangod (09-10-2012)

  • #11
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,376
    Thanks
    263
    Thanked 32 Times in 31 Posts
    thanks everyone im glad i finally got it, i guess i learned what happens when one part of the javascript fails, i would assume it would all fail or that i would get a message so not sure what happened because it ran the first if and then failed and the typo was on the third if statment that i added. Strange how the first one worked and then nothing else. lesson learned on several levels here.

    Appreciate the help all.


  •  

    Posting Permissions

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