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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:13:50+00:00 2026-05-27T23:13:50+00:00

Related to this question here . I’m trying to iterate through a series of

  • 0

Related to this question here.

I’m trying to iterate through a series of forms on a page and do some “things” with said forms, but I can’t get it to work. Code is below:

HTML:

<div id="placement">
<h3>Placement</h3>
<form action="" id="placement-form">
  <input type="text" class="site" value="Site" title="Site" onfocus="clickclear(this, 'Site')" onblur="clickrecall(this,'Site')" />
  <input type="text" class="placementdesc" value="Placement description" title="Placement description" onfocus="clickclear(this, 'Placement description')" onblur="clickrecall(this,'Placement description')" />
  <input type="text" class="placementtype" value="Placement Type" title="Placement Type" onfocus="clickclear(this, 'Placement Type')" onblur="clickrecall(this,'Placement Type')" />
  <input type="text" class="size" value="Size" title="Size" onfocus="clickclear(this, 'Size')" onblur="clickrecall(this,'Size')" />
  <input type="text" class="pricing" value="Pricing" title="Pricing" onfocus="clickclear(this, 'Pricing')" onblur="clickrecall(this,'Pricing')" />
  <select class="servetype" title="Serve Type">
    <option>STD – Standard trafficking type (ie, regular display banners)</option>
    <option>SSV – Site-served (no ad server tracking)</option>
    <option>PIX – Pixel</option>
    <option>CCD – Click command</option>
    <option>PCC – Pixel and Click command</option>
    <option>RMV – Rich Media Video</option>
    <option>RME – Rich Media Expand</option>
    <option>RMO – Rich Media Other</option>
  </select>
  <span id="placement_span"></span>
</form> 
<input type="button" value="+" class="addRow" />   
 </div>

jQuery (this is for the “addRow” button):

var uniqueId = 1;
$(function() {
$('.addRow').click(function() {
    var formCopy = $("#placement-form").clone();
    var formCopyId = 'placement-form' +uniqueId;
    formCopy.attr('id',formCopyId);
    $('#placement').append(formCopy);
    uniqueId++;
    });
});

Here’s the script I’m trying to get to work:

function getPlacement() {
    $('.placement-form').each(function(){
        var site, placement_desc, placementtype, size, pricing, servetype;  
        site = document.getElementById("site").value;
        placement_desc = document.getElementById("placementdesc").value;
        placementtype = document.getElementById("placementtype").value;
        size = document.getElementById("size").value;
        pricing = document.getElementById("pricing").value;
        servetype = document.getElementById("servetype").value;
        document.getElementById("placement_span").innerHTML = '<br />'+site+'_'+placement_desc+'_'+placementtype+'_'+size+'_'+pricing+'_'+servetype;
        return false;
    });
}

My understanding of the .each() function is that it wil loop through the DOM for each instance of that form named “placement-form” and then run the next few statements. Is this incorrect? Would appreciate some help on this!

  • 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-27T23:13:51+00:00Added an answer on May 27, 2026 at 11:13 pm

    The mistake you’ve made is that your selector in the .each command uses .placement-form – which looks for any element with the class placement-form… you’re creating elements with the id of placement-form(x).

    I would suggest adding a class to each newly created form (as id’s must be unique, but classes have no such requirement).

    var formCopy = $("#placement-form").clone().addClass('placement-form');
    

    or just make sure the original has this class:

    <form action="" id="placement-form" class="placement-form">
    

    Then your .each should work as-is.

    Another option is to use the starts-with selector but i’d consider this the worse option as it’ll be slower:

    $('[id^="placement-form"]').each(...)
    

    The above looks for any element where the id starts with placement-form.


    Edit: Here’s some pointers to getting your getPlacement function working

    1) Change the span with the id placement_span to a class. You will end up with many of these and as previously pointed out id’s must be unique. This will also aid you in finding the right one when looping over all placement_form‘s

    2) Remove the return false, as this stops the .each at the first matched form (meaning only the first one works)

    3) Change getPlacement to use jQuery, especially providing the second parameter to the selector to narrow down the search to the current form. Here’s some working code:

    $('.placement-form').each(function(){
        var $form = $(this);
        var site, placement_desc, placementtype, size, pricing, servetype;  
        site =  $(".site",$form).val()
        placement_desc = $(".placementdesc",$form).val();
        placementtype = $(".placementtype",$form).val();
        size = $(".size",$form).val();
        pricing = $(".pricing",$form).val();
        servetype = $(".servetype",$form).val()
        $(".placement_span",$form).html('<br />'+site+'_'+placement_desc+'_'+placementtype+'_'+size+'_'+pricing+'_'+servetype);
        });
    }
    

    Live example: http://jsfiddle.net/zu8ZJ/

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

Sidebar

Related Questions

This question is related to the one I asked here . I'm trying to
I think my question may be related to this question here but i'll ask
This is related to this question here, but with a slight twist: instead of
I don't know if i should ask this question here, but it's related to
Related to this question here , but I decided to ask another question for
First of all, I looked up this related question in here but the solution
This is related (but fairly independent) to my question here: Why SELECT N +
not sure if this question should be here or in serverfault, but it's java-related
This is related to my previous question here . I want 4 divs (absolute
I have searched here, GooBingHooVista'd the world and read this related question for VS

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.