Results 1 to 6 of 6

Thread: [RESOLVED] [JavaScript] Validate Values

  1. #1

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,754

    Resolved [RESOLVED] [JavaScript] Validate Values

    I'm wanting to validated that all my required inputs have values in them. My thinking is that JavaScript is a functional language, so there must be something like this:

    Pseudo code:
    Code:
    (From ele As Element In ParentElement Where ele.Required && (ele.Value == "" | ele.Value == null)).length == 0
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  2. #2
    Frenzied Member tr333's Avatar
    Join Date
    Nov 2004
    Location
    /dev/st0
    Posts
    1,605

    Re: [JavaScript] Validate Values

    Do you need to validate in JavaScript, or are you just wanting to validate on form submission? You should consider using the Constraint Validation API in HTML5, in combination with specific input types instead of just using "text" inputs everywhere. This allows you to just add standard attributes to your form elements for automatic validation by the browser.

    https://www.wufoo.com/html5/
    http://diveinto.html5doctor.com/forms.html

    https://jsfiddle.net/wq431w96/

    https://developer.mozilla.org/en-US/...int_validation
    http://html5please.com/#form%20validation
    http://caniuse.com/#feat=form-validation
    https://developer.mozilla.org/en-US/...orm_validation
    CSS layout comes in to the 21st century with flexbox!
    Just another Perl hacker,

  3. #3

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,754

    Re: [JavaScript] Validate Values

    I should expand a little bit, there are multiple forms and all of which have some elements that have the required attribute. I'm actually using my accordion control that I have a codebank submission and in each div element I have a form. On the last div I have the submit button and I'm needing to validate that all elements that are required have something in it.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  4. #4
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: [JavaScript] Validate Values

    Why not simply "remove" a "got my REQUIRED value" CSS class from the INPUT when it is filled.

    Then when you go to SUBMIT just do a

    $("#someParentDiv").find(".still-waiting-for-required").length != 0

    [edit] this is assuming you have jQuery setup on the page [/edit]

    [edit2] you must be if you are using the ACCORDION [/edit2]
    Last edited by szlamany; Jan 20th, 2016 at 11:26 AM.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  5. #5
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: [JavaScript] Validate Values

    And if you wanted to color them all red

    Code:
    if ($("#someParentDiv").find(".still-waiting-for-required").length != 0) {
        $("#someParentDiv").find(".still-waiting-for-required").addClass("color-me-red");
        $("#someDialog").dialog("open")........ 
                  // in the CLOSE event of the DIALOG do a .removeClass("color-me-red")
    }
    If you use jQuery like the above you should cache the "repeated" use of the same "selectors" as there is overhead in those calls that you should avoid repeat calling...

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  6. #6

    Thread Starter
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,754

    Re: [RESOLVED] [JavaScript] Validate Values

    What I wound up doing is adding a class name for each required element in each tab and then in the submit button's click event looping through each required element checking if one of the values is empty or null, if one is empty or null then I alerted the user and used the return keyword to exit the function prematurely.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

Posting Permissions

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



Click Here to Expand Forum to Full Width