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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:02:59+00:00 2026-05-27T16:02:59+00:00

my first post here. I’m not new to JQuery, but I find complex coding

  • 0

my first post here. I’m not new to JQuery, but I find complex coding quite difficult (naturally!). I will explain my problem as clearly as possible. I’m using elgg so some code here will be elgg specific. That will not be an issue.

I’m creating a page that allows my users to add questions to something. They can add questions using the following method:

echo "<div id='ques_holder'>";
echo "<table><tr><td style='width:380px;padding-right:10px;'>";
    echo "<b>Question:</b> ";
    echo elgg_view("input/text", array('internalname' => 'ques_','internalid' => 'ques_'));
echo "</td><td style='width:90px;'>";
    echo "<b>Answer:</b> ";
    echo elgg_view("input/pulldown", array('internalname' => 'ans_','internalid' => 'ans_', 'options_values' => array('true' => 'True', 'false' => 'False')));
echo "</td></tr></table>";
echo "</div>";

I now want to make it possible to add more than one question at a time so I use the following cloning code to accomplish this:

var quescount = 0;

function add_question() {
quescount++;
var clone = $("#ques_holder").clone(false);
$("*", clone).add(clone).each(function() {
    if (this.id) {
        this.id = this.id + quescount;
    }
    if (this.name) {
        this.name = this.name + quescount;
    }
});
$("#interact_input_questions_adder").append(clone);
}

This is all working fine. New questions are added and their ids and names are updated with a number (quescount) as well as their child elements as well. The problem comes with the following part. I’m trying to get all the input names and values together for sending via ajax to a php file. This is where my code is breaking. I was trying a double .each() call (one inside the other), but something in my coding isn’t working. The code is below:

function save_questions(){
    var qrange = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20];
    var activity = "<?php echo $activity;?>";
    datastr = "&activity=" + activity;
    jQuery.each(qrange , function(index,value){
        $("#ques_holder"+value).find('input').each(function(){
            datastr += $(this).attr('name');
        });
    });
    alert(datastr);
}

Things to Consider
The types of inputs coming in could change each time (the one I gave is just one example)
The elgg coding is not breaking things
The qrange array is simply to restrict the number of questions (which I haven’t put into the add_question() function just yet)

I guess what I’m wondering is…can you do a .each() inside a jQuery.each(), and according to my coding, how can I get the names of all those inputs found inside those each calls?

Any help much appreciated. Don’t feel shy to ridicule me for my ugly coding, I taught myself through trial and error from sites like stackoverflow. 😉

EDIT: after severe face-palming I realised the mistake was an oversight of not using an “onclick” when I should be. The final stuff is as follows and was actually supplied by RightSaidFred who for some reason then removed his answer.

function save_questions(){
    var qrange = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20];
    var activity = "<?php echo $vars['activity'];?>";
    datastr = "&activity=" + activity;
    jQuery.each(qrange , function(index,value){
        $("#ques_holder"+value).find('input').each(function(input_idx, input){
            datastr += "&" + $(input).attr('name') + "=" + $(input).attr('value');
        });
    });
    alert(datastr);
}
  • 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-27T16:03:00+00:00Added an answer on May 27, 2026 at 4:03 pm

    Why don’t you put a class to all the ‘ques_holder’ divs, for example

      <div id='ques_holder' class='holder'>
    

    Then, you just have to do one each to grab all the inputs

     $("div.holder input").each(function() {
          var name = $(this).attr('name'); // if you need the name
          var val = $(this).val();   // if you need the value
          var parent = $(this).closest('div.holder').attr('id'); // if you need to know the parent number
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

first post here, I come in peace :) I've searched but can't quite find
First post here, I have tried searching but couldn't find what I'm looking for
my first post here. I am not much of a programmer, I can tailor
Frequent visitor but first post here on StackOverflow, I'm hoping that you guys might
My first post here - it's a great site and I will certainly do
this is my first post here on StackOverflow and I'm quite excited about it
this is my first post here. I'm using an existing Flash widget but would
(First post here ... new to iOS.) In my xTableViewController in the the didSelectRowAtIndexPath
this is my first post here but I've been a frequent reader of various
This is my first post here, but I've using this site regularly to help

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.