Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7840595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:50:26+00:00 2026-06-02T15:50:26+00:00

This is a validation script This code runs when the user presses the submit

  • 0

This is a validation script
This code runs when the user presses the submit button on a form
It loops thru all mandatory fields (entered in an array) and…
1. checks if the element is hidden
2. if not is it empty?
3. if not is it false? (I use false as a value for non selectable options)
And all this sets a variable to true or false.

// when submitting the registration form
function mandatoryCheck() {
    jQuery('.tx-powermail-pi1_formwrap_1723 form.tx_powermail_pi1_form').submit(function(event) {
        var success = false;
        var element;
        jQuery.each(mandatoryFields, function(index, value) {
            element = jQuery('#powermaildiv_uid'+value+' input, #powermaildiv_uid'+value+' select')

            element.each(function() {
                // add class required to all fields
                jQuery(this).addClass('required');

                // is the element hidden, return true
                if(jQuery(this).hasClass('fieldHidden') == true || jQuery(this).is(':disabled')) {
                    success = true;
                } else {
                    // is the input field empty, return false
                    if(jQuery(this).val().length === 0) {
                        success = false;

                    // is the input field not empty, return true
                    } else {
                        // is the input field false, return false
                        if(jQuery(this).val() == 'disabled') {
                            success = false;
                        } else {
                            success = true;
                        }
                    }
                }

                // For each element add/remove validation class
                if(success == false) {
                    jQuery(this).addClass('validation-failed').removeClass('validation-passed');
                } else {
                    jQuery(this).addClass('validation-passed').removeClass('validation-failed');
                }
            });
        });

        // if succes is false, show error message and return false
        if(success == false) {
            jQuery('#c1799').fadeIn().css('display', 'block');
            event.preventDefault();
            return false;
        } else {
            jQuery('#c1799').fadeOut();
        }
    });
}

It works in firefox, chrome ie9 but not ie 7 or 8.
IE7 or 8 adds classes to the elements all random.
It seems like if I validate a select element it passes but an input field fails

What can be wrong?

Edit:
Here is the page: http://asdf.patrikelfstrom.se/index.php?id=267
Enter 1234 if in the little form that shows up
JS: http://asdf.patrikelfstrom.se/typo3conf/ext/gc_fm/res/js/ShowAndHideFields.js

If you press submit (absenden) the field Türnummer should be green (as it is in chrome, firefox etc.) but in ie7/8 it is red.

If you click on Wähle… (The select box) and choose Wohnung the fields under it becomes enabled and if you press submit now Türnummershould be red since the element is visible and empty.
This seems to work but if you click on the select box again and choose einfamilienhaus.
The fields are disabled and should now be green when submitting but this is not the case in IE7/8.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T15:50:27+00:00Added an answer on June 2, 2026 at 3:50 pm

    I think you need to loop through element, as it will be a collection of objects, so you would do…

    // is the element hidden, return true
    element.each(function() {
       if($(this).hasClass('fieldHidden') == true) {
       ...
    
    })
    

    Well, just to show the point, depends on your code what you need to actually change

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got this validation script for my form (a survey). It loops through all
This is a form validation that will hide the submit button if the input
I'm using this jQuery Validation script to submit my form(s), but I need some
I've got this piece of code in my jquery validation script: resetForm: function() {
I wrote my custom jquery validation script to validate the fields in the form
I used a JQuery Validation script for validating an HTML Form. This worked perfectly
I have been struggling with this jQuery Validation Plugin. Here is the code: <script
I want to create a validation range in cell A1. This validation allow user
How to solve this HTML 5 validation error related to Facebook like button? Here
How do I validate checkboxes using this validation script? I've tried many different ways

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.