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

  • SEARCH
  • Home
  • 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 7412791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:35:46+00:00 2026-05-29T06:35:46+00:00

Below is my validation() function which controls some messages in an alert: function validation()

  • 0

Below is my validation() function which controls some messages in an alert:

function validation() {

    var marks = parseInt($("#total-weight").text());    
    var _qid = "";
    var _msg = "";

    var alertValidation = "";
    // Note, this is just so it's declared...
    $("tr.optionAndAnswer").each(function() {


        _qid = $("td.qid",this).text();
        _msg = "You have errors on Question Number: " + _qid + "\n";

        $(".txtWeightRow",this).each(function() {


            if (!this.value) {
                alertValidation += "\n\u2022 Please enter in a figure for Number of Marks for this Question\n";
            }

            if (alertValidation != "") {
                return false; //Stop the each loop 
            }
        });


        if(alertValidation != ""){
            return false;
        }
    });

// SPLIT

            if($("#total-weight").text() < '0')
{
 alertValidation += "Your Total Session Marks Remaining does not equal 0 \n\n\u2022 You Need To Remove " + Math.abs(marks) +  " Marks";   
}

        else if($("#total-weight").text() > '0')
{
 alertValidation += "Your Total Session Marks Remaining does not equal 0 \n\n\u2022 You Have " + marks +  " Marks Remaining";   
}

    if (alertValidation != "") {
        alert(_msg + alertValidation);
        return false;
    }

    return true;
}

I have included a //SPLIT comment in the function. The reason I have done this is because if you look at the `$(“.txtWeightRow”,this).each(function() {, that goes into a table row so it has a question number (table row number) attached to that error. But below the split you see an if and else if statements, these statements don’t deal with anything in a table row so it should not have a question number (table row number) attached in the alert.

Now lets say for eaxmple if you look at the condition below the //SPLIT that the #total-weight > 0, it displays this alert below:

You have errors on Question Number: 1
Your Total Session Marks Remaining does not equal 0 

• You Have 5 Marks Remaining

The above is incorrect as it is not in a table row so it should not display a question number. The alert instead should display this:

Your Total Session Marks Remaining does not equal 0 

• You Have 5 Marks Remaining

Why is it displaying the question number and how can I get rid of “You have errors on Question Number: 1” from the alert?

Also the alert messages in the conditions below the //SPLIT should only appear after there is no errors in the all the table rows. If there is an error in any table row, then don’t display the alert above, but if there is no error in any table row, then display the alert above if the condition to show the alert is met. So how can this be done?

  • 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-05-29T06:35:47+00:00Added an answer on May 29, 2026 at 6:35 am

    You have some initial value set in _msg variable which is not applicable in this condition so just set it to _msg = ''. Also instead of += just use = for alertValidation message because it is already empty. Try this.

    if(alertValidation == ''){
      _msg = '';
      if($("#total-weight").text() < '0')
      {
          alertValidation = "Your Total Session Marks Remaining does not equal 0 \n\n\u2022 You Need To Remove " + Math.abs(marks) +  " Marks";   
      }
    
      else if($("#total-weight").text() > '0')
      {
          alertValidation = "Your Total Session Marks Remaining does not equal 0 \n\n\u2022 You Have " + marks +  " Marks Remaining";   
      }
    }
    
    if (alertValidation != "") {
       alert(_msg + alertValidation);
       return false;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

$('td.qid').text(). The code above will determine which row the alert is refering to. Below
Below I have a Json function and some php code which it retrieves. JavaScript
I am using the following javascript for form validation: <script type=text/javascript> function validate_form (
I am currently using a email form, which posts some text once the email
Below is my validation function: function validation() { alertValidation= ; // Note, this is
My below mentioned code still submits form on special character in name field. Validation
As you can see below, in the constructor I'm instantiating a validation object so
Where is the proper place to perform validation given the following scenario/code below: In
Below is my current char* to hex string function. I wrote it as an
Below is part of the XML which I am processing with PHP's XSLTProcessor :

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.