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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T21:33:15+00:00 2026-05-12T21:33:15+00:00

just trying to tie up a few loose odds and ends here. I have

  • 0

just trying to tie up a few loose odds and ends here. I have the following code:

$(function(){
    // start a counter for new row IDs
    // by setting it to the number
    // of existing rows
    var newRowNum = 2;

    var quantity = 1;
    // bind a click event to the "Add" link
    $("a").bind("click", function() {
        // increment the counter
        newRowNum += 1;

        // get the entire "Add" row --
        // "this" refers to the clicked element
        // and "parent" moves the selection up
        // to the parent node in the DOM
        var addRow = $(this).parent().parent();

        // copy the entire row from the DOM
        // with "clone"
        var newRow = addRow.clone();

        // set the values of the inputs
        // in the "Add" row to empty strings
        //$('input', addRow).val('');
        //$('name', addRow).val('os' + newRowNum);

        // replace the HTML for the "Add" link 
        // with the new row number
        $('td:first-child', newRow).html('<input type="hidden" name="on' + newRowNum + '" value="Recipient Address ' + (newRowNum - 1) + '">Recipient');

        // insert a remove link in the last cell
        $('td:last-child', newRow).html('<a href="" class="remove">Remove<\/a>');

        // loop through the inputs in the new row
        // and update the ID and name attributes

        $('input:hidden', newRow).attr('id','on' + newRowNum ).attr('name','on' + newRowNum );
        $('textarea', newRow).attr('id','os' + newRowNum ).attr('name','os' + newRowNum );

        // insert the new row into the table
        // "before" the Add row

        addRow.before(newRow);

        document.tp01.quantity.value = newRowNum-1;
        quantity += 1;
        // add the remove function to the new row
        $('a.remove', newRow).click(function(){
            $(this).parent().parent().remove();
            document.tp01.quantity.value = quantity-1;
            return false;               
        });

        // prevent the default click
        return false;
    });

});

What I am trying to do is use a conditional block here which tests to see if quantity = 6 and if so, not allow the user to add a new row (email recipient). I have tried the following:

    if(quantity < 7) {
        addRow.before(newRow);
        };

to test if quantity is less than seven (6 max) and only then allow them to add a new row. This does not work.
I have also tried:if(quantity < 6) {
quantity += 1;
};

to test if the quantity was less than 6 and if so, add one to the value. Otherwise nothing. This does not work.

Basically, what I need to do is, everytime someone adds a row, I need to increment the quantity (which it is now doing correctly) but not allow them to add more than 6 rows (which it is NOT doing correctly).

As always, your help is appreciated.

Dave

  • 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-12T21:33:15+00:00Added an answer on May 12, 2026 at 9:33 pm

    Try pulling quantity out of the document.ready.

    var quantity = 0;
    
    $(function()...
    

    My guess is that the quantity variable is no longer in scope when you go back into the event handler.

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

Sidebar

Related Questions

just trying to test for equality in this piece of code, but getting a
Just trying to canvas some opinions here. I was wondering how people go about
Just trying to understand that - I have never used it before. How is
Just trying to confirm an impression: it seems enums in EF5 + Code First
In a UNIX-y way, I'm trying to start a process, background it, and tie
Just trying to write a function that gets clock hand angles, but getting an
Just trying to optimize a SQL Query. SELECT Code, COUNT(*) FROM tblData WHERE ListID
Just trying to get diff to work better for certain kinds of documents. With
Just trying to still get my head around IOC principles. Q1: Static Methods -
Just trying to establish whether prototype can do something like $$('#ID a:last').css('color','#111'); Any ideas

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.