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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:26:38+00:00 2026-06-11T09:26:38+00:00

New to jQuery, requesting assistance with something I’m having trouble figuring out. A cloned

  • 0

New to jQuery, requesting assistance with something I’m having trouble figuring out.

A cloned table row contains an <input type="text" name="dt[]" id="dt1"> field. Below is the template row that gets cloned.

<table id="MyTable" name="MyTable">
    <tr name="tr3" id="tr3">
        <td>
            <input type="text" name="dt[]" id="dt1">
        </td>
        <td>
            <input type="file" name="fff[]" id="ff1">
        </td>
    </tr>
</table>

The user could potentially create several of these fields and I am trying to figure out how to loop through them all and verify there is text in them before submitting the form.

Note that I must use the jQuery .on() method to access the form elements. How would the loop need to be coded? Initially, I’ve been trying this (EDITED):

$(document).on('click','#sub1',function() {
    var d1 = $("[name^=dt]").val();
    alert(d1);
    if (d1 !=""){
        $("#TheForm").submit();
    } else {
        alert("Empty fields!");
    }
});

And this:

var d1 = $("#dt1").val();
alert(d1);

And this:

var d1 = $("#^dt").val();
alert(d1);

but haven’t been able to get at the data.


EDIT: As requested, this code clones the row:

$(document).on('click', '#add_row', function() {
    $("table#MyTable tr:nth-child(4)")
        .clone()
        .show()
        .find("input, span").each(function() {
            $(this)
                .val('')
                .attr('id', function(_, id) {
                    var newcnt = id + count;
                    return id + count;
                    });
        })
        .end()
        .appendTo("table")
        ;

    count++;
    if (count == 2) {
        $('#add_row').prop('disabled', 'disabled');
    }
}); //end add_row Function
  • 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-11T09:26:39+00:00Added an answer on June 11, 2026 at 9:26 am

    Your HTML is not in correct format. you should do:

    <input type="text" name="dt[]">
    

    and then loop over like:

    $('input[name^=dt]').each(function() {
      // code
      alert( this.value ); // $(this).val()
    });
    

    What you’re trying to do can not be possible with id attribute, but possible with name attribute. id should always be unique.


    Beside that

    You can use a common class name to all inputs and then loop over then like:

    $('input.common_cls').each(function() {
      // code
    });
    

    Note

    "#^dt" is not a valid selector at all. Correct syntax would be

    'input[name^=dt]'

    OR

    input[id^=dt].


    You may implement the validation like below

    // this function will return true if no empty
    // input exists, otherwise it will return false
    
    function noEmptyExists() {
        return $('input[name^=dt]').filter(function() {
            return !$.trim( this.value );
        }).length === 0;
    }
    
    $(document).on('click','#sub1',function() {
       if( noEmptyExists() ) {
          alert('Success');
       } else {
          alert('Failed');
       }
    });
    

    Working sample


    According to PROGRESS UPDATE

    this.val() is wrong.

    Change this line to:

    $(this).val()
    

    After a discussion in Chat and after solving the clone issue

    Full code

    $(document).ready(function() {
        var count = 1;
        alert('doc ready');
        var row = $("table#MyTable tr:eq(1)");
        $(document).on('click', '#sub1', function() {
            if (noEmptyExists()) {
                alert('Success');
            } else {
                alert('Failed');
            }
        });
    
        $(document).on('click', '#add_row', function() {
            row.clone(true).find("input").each(function() {
                $(this).val('').attr('id', function(_, id) {
                    var newcnt = id + count;
                    return id + count;
                });
            }).end().appendTo("table");
        });
    
    });
    
    function noEmptyExists() {
        return $('input[name^=dt]').filter(function() {
            return !$.trim(this.value);
        }).length === 0;
    }
    

    Working sample

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

Sidebar

Related Questions

I'm having trouble getting tinyMCE to work with the new jQuery 1.4.2 on IE6.
Im new in jQuery so sure that i am doing something wrong :(. Matter
Having a bit of trouble getting jQuery and Prototype working together. The error console
I am having a problem requesting a random number from random.org using jQuery. When
I am brand new to Jquery and have run into something that if answered
When writing a new jQuery plugin is there a straightforward way of checking that
Using jQuery UI 1.8rc3 combined with the new jquery.effects.fade.js code, I've been able to
I've been trying to use the new jquery-ui, and all but the resizable function
I have application that brings response via Ajax and creates 5-20 new jQuery click
Example: var $doesNotYetExistInTheDOM = $('<span/>'); // create new jQuery element // outside of the

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.