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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:18:40+00:00 2026-06-05T06:18:40+00:00

Hello I need to save multi values and update database using ajax.. I’m working

  • 0

Hello I need to save multi values and update database using ajax.. I’m working on Yii framework..

in the first I need to send data using ajax as json but I have wrong on results.

Live code:
http://jsfiddle.net/kxJwp/2/

My javascript code is:

$("#save").live('click', function(){
    var showtimes = [];
    var values = {};
    $('li inputs').each(function() {
        values[$(this).attr('name')] = $(this).val();
    });
    $('li').each(function(i) {
        showtimes[i]=values;
    });
    alert(JSON.stringify(showtimes));
});

Javascript output:

It’s output last one li values x number of li

inputs:

<li>
    <input name="show_id" class="show_id att" type="hidden" value="" />
    <input name="movie_id" class="movie_id att" type="hidden" value="" />
    <input name="cinema_id" class="cinema_id att" type="hidden" value="" />
    <input name="status" class="status att" type="hidden" value="" />
    <input name="times" class="timesArray att" type="hidden" value="" />
<li>
<li>
    <input name="show_id" class="show_id att" type="hidden" value="" />
    <input name="movie_id" class="movie_id att" type="hidden" value="" />
    <input name="cinema_id" class="cinema_id att" type="hidden" value="" />
    <input name="status" class="status att" type="hidden" value="" />
    <input name="times" class="timesArray att" type="hidden" value="" />
<li>
  • 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-05T06:18:43+00:00Added an answer on June 5, 2026 at 6:18 am

    You are seeing only one row because you have only one object, whereas you need an array of objects, so declare an array first, and then keep adding the objects to it. Something like this:

    $("#save").live('click', function(){
      var showtimes = [];    // Create empty javascript array
      var objec={};
      $("li").find("input").each(function(index) {           // Iterate over inputs
    
        objec=new Object; // to create a new object for every matched element
    
        objec[$(this).attr('name')]=$(this).val()+'avla';
        showtimes[index]=objec;  // Add object to array
      });
    
      var json = JSON.stringify(showtimes);
      alert(json);
    });
    

    Code explanation:
    Use the inbuilt index of each(), by passing the index to the function like: function(index){...}.

    Edit: objec=new Object; is needed to avoid getting repeated values, because each time the same object was getting added to the array, but with new, a new object is created each time and that is added to the array.

    Update: A better way to select the lis would be using a selector such as : $("li:has(input)") and then cycle through the children:

    $("#save").live('click', function(){
        var showtimes = [];
        var values = {};
        $("li:has(input)").each(function(i){
            values = new Object;
            $(this).children().each(function(){
                values[$(this).attr('name')]=$(this).val();
            });
            showtimes.push(values);
        });
        alert(JSON.stringify(showtimes));
    });
    

    Edit: The output(arrays formed) in both the above samples is different.

    Output for code sample 1:

    json=[{"show_id":"1avla"},{"movie_id":"2avla"},{"cinema_id":"3avla"},{"status":"4avla"},{"times":"5avla"},{"show_id":"6avla"},{"movie_id":"7avla"},{"cinema_id":"8avla"},{"status":"9avla"},{"times":"0avla"}]
    

    Output for code sample 2:

    json=[{"show_id":"1","movie_id":"2","cinema_id":"3","status":"4","times":"5"},{"show_id":"6","movie_id":"7","cinema_id":"8","status":"9","times":"0"}]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello Everyone, I am working on an application in which i need to save
Hello I need to do something like this: UPDATE tbl SET pozn=CONCAT(pozn, '+attach_str+') WHERE
Hello friends i need a book/ tutorials for rails without using scoffold. All the
Hello everyone I would have a value for the need to save every time
note: this is in C++ but using C-style strings hello SO, I'm working on
What I've tried Hello Guys, I first created a database which I've filled with
Hello I need to have multiple language support of my django admin application.I can
hello i need to do the following: move a node from jstree to another
hello guys i need to sort some elements of integer in an integer array
Hello guys i need to capture the output of an external command, herefore I

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.