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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:35:05+00:00 2026-06-03T09:35:05+00:00

I know this is a similar question to my previous one however its slightly

  • 0

I know this is a similar question to my previous one however its slightly different.

I have this script adding each ‘dropped’ element to a list. Now i need it adding into a variable / hidden field so i can pass it to the next page via a form.

When i run it at the moment. It alerts for each one however, it does it not just for every item dropped but if there are 10 items dropped it will run 10 times per item droped rather than once per item dropped.

Any help would be great.

//Record and add dropped items to list
            var txt = $("#listbox");
            var dtstart = copiedEventObject.start + '\n'
            var caltitle = copiedEventObject.title

            var txt = $('#listbox');     
            txt.append("<li class ='listItem'> "+dtstart +"</li>")

            var listItems = $('.listItem'); 

                $('#calendarform').submit(function() {

                        listItems.each(function(){   //For each event do this:

                            alert( listItems.text() );                  

                        });

                    return false;

                });

            // remove the element from the "Draggable Events" list
            $(this).remove();   
  • 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-03T09:35:06+00:00Added an answer on June 3, 2026 at 9:35 am

    the problem lies in this code

    listItems.each(function(){  //For each event do this:
        alert( listItems.text() );                  
    });
    

    you are alerting the text of all the list items for each list item.

    use jQuery(this) to access the current item within an each block

    listItems.each(function(){   //For each event do this:
        alert( $(this).text() );                  
    });
    

    Assuming your code is within a drop event handler, you are also adding a submit handler each time you drop. This means that each time you drop, you queue up another submit event. This is probably not desired. Move this submit(function(){}) block outside your drop handler to prevent it from firing that function more than once.

    $('#calendarform').submit(function(e) {
        var listItems = $('.listItem'); 
        listItems.each(function(){   //For each event do this:
            alert( listItems.text() );                  
        });
        e.preventDefault();//stop normal behavior
        return false;
    
    });
    

    and to create elements on the fly you just pass jQuery the html, and append it to your form.

    $('<input type="hidden" name="listItem[]"/>').appendTo("#calendarForm").val(listItem.text())
    

    you may have to fiddle with the name element to get it to submit as an array in your server side language, but you’re also within an each loop, which provides you with an index, so you can do the following.

    $('#calendarform').submit(function(e) {
            var form = $(this);
            var listItems = $('.listItem'); 
            listItems.each(function(index){   //For each event do this:
                var listItem = $(this);
                $("<input type='hidden'/>").val(listItem.text()).appendTo(form).attr('name', 'listItem[' + index + ']');
            });
            e.preventDefault();//stop normal behavior
            return false;
    
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this question is similar to several previous ones, but I can't find
First of all, I know I asked a similar question before but this one
I know that this is a repeated question. I have found very similar questions
I know this sounds strange earlier I asked about similar question in one of
I know that this question is very similar to the question posted here .
This question was inspired by a similar question: How does delete[] know the size
I'm asking a question similar to this, but with python 2.7 instead. I know
I know there are questions similar to this one, but I've not found a
I know there have been some similar questions to this, but they haven't helped
my question is similar to this one: OpenCV: Detect blinking lights in a video

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.