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 6337909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:20:31+00:00 2026-05-24T19:20:31+00:00

I have a program that I am creating that creates task inputs dynamically. My

  • 0

I have a program that I am creating that creates task inputs dynamically. My issue is that I am trying to create some validation on the form submission to check for anything that might be wrong.

I am running into an issue with looping through the classes. I think the main issue is the “if” validation.

Here is the code that I have right now:

function(){
//some validation for the tasks....Loop through page create an instance of the message. 
var numOfTaskName = $('.taskNameInput').length
alert(numOfTaskName);
var i=0;
while (i<=numOfTaskName)
{

        if($(".taskNameInput").val()=="Task Name" || $(".taskNameInput").val().length <1) 
        {
            $("#message").html("<div class='errors'>At least one task is required. This error will show if you have not entered at least one task or you have an extra task that is not needed on the task tab. Please add a task or delete the extra task.</div>");

            i++;
            return false;

        } i++;
} 

EDIT: Oh by the way this validation actually works for the first class. But not for any other dynamically created tasks(classes).

ANOTHER EDIT

Alright…the issue that I am having is nesting this loop in my submit function. Please see below for my submit function. On submit I need to validate all the “taskNameInput” classes.

$("form").submit(
function(){
        $.blockUI({ message: 'Processing...please wait.',

    css: { 
        border: 'none', 
        padding: '15px', 
        backgroundColor: '#000', 
        'border-radius': '10px',
        '-webkit-border-radius': '10px', 
        '-moz-border-radius': '10px', 
        opacity: .5, 
        color: '#fff' 
        }});

        $.post("projectSetupCB.php", 
        $("#newProject").serialize(), 

        function(list){
        $("#message").removeClass().html(list);
        $("html,body").animate({scrollTop:0},'slow');
        $.unblockUI()

        });


return false; 
 });
  • 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-24T19:20:33+00:00Added an answer on May 24, 2026 at 7:20 pm

    When you use $(".taskNameInput") in your loop, you’re getting the same first object every time. You should probably use .each() to iterate all the items in $(".taskNameInput") and return false from the each function when you want to stop the iteration.

    function(){
    $('.taskNameInput').each(function() {
        var o = $(this);
        if (o.val() == "Task Name" || o.val().length < 1) {
            $("#message").html("<div class='errors'>At least one task is required. This error will show if you have not entered at least one task or you have an extra task that is not needed on the task tab. Please add a task or delete the extra task.</div>");
            return(false);   // break out of .each() loop
        }
    });
    

    To use this in your submit function, you probably want to first make it a local function in the submit function that you can call. Then, in your submit function, you can call it and act on it’s return value:

    $("form").submit(function() {
    
       // declare local function for validation
       function validateInputs() {
           var ok = true;
           $('.taskNameInput').each(function() {
               var o = $(this);
               if (o.val() == "Task Name" || o.val().length < 1) {
                   $("#message").html("<div class='errors'>At least one task is required. This error will show if you have not entered at least one task or you have an extra task that is not needed on the task tab. Please add a task or delete the extra task.</div>");
                   ok = false;      // set return flag
                   return(false);   // break out of .each() loop
               }
           });
           return(ok);
       }
    
       // block the UI
       $.blockUI({ 
            message: 'Processing...please wait.',
            css: { 
                border: 'none', 
                padding: '15px', 
                backgroundColor: '#000', 
                'border-radius': '10px',
                '-webkit-border-radius': '10px', 
                '-moz-border-radius': '10px', 
                opacity: .5, 
                color: '#fff' 
            }
        });
    
        // now validate the input and return false if it doesn't validate
        if (!validateInputs()) {
            $.unblockUI();
            return(false);
        }
    
        // send our form data
        $.post("projectSetupCB.php", 
            $("#newProject").serialize(), 
            function(list) {
                $("#message").removeClass().html(list);
                $("html,body").animate({scrollTop:0},'slow');
                $.unblockUI();
            }
        );
    
        return(false);     // we already posted, don't let the form post itself
     });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been tasked with creating a program that will generate an amortization schedule.
I have a program that creates a Windows user account using the NetUserAdd() API
I am writing a program that creates a stack using linked lists. I have
I have a program that creates a C# class from a text file. The
I want to create a program that creates .txt files with random characters, but
I have a multi-threaded Delphi program creating multiple instance of some classes, and I
everyone: Im creating a program that is able to create Matrices and and perform
I have program that has a variable that should never change. However, somehow, it
I have program that runs fast enough. I want to see the number of
I have a program that spits out both standard error and standard out, and

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.