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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:03:25+00:00 2026-06-06T00:03:25+00:00

I have an array and it has some data in it. This array contains

  • 0

I have an array and it has some data in it. This array contains id, firstname, lastname, email, phone. I also have five form input elements. Now I want to add data in array in these elements. For example, ID should be inserted in ID form field, name should be inserted in name input element etc. how can I achieve this?

here is my code

insert_data_in_form: function(data) {
    var form = $("#dataform");
    var form_arr = new Array();

    form.each(function(i) {
        var form_el = form.children("input[type='textfield']");
        form_arr.push(form_el);
        console.log(data.length);
        //for(var j = 0; j < 5; j++) {
            form_el.val(data[i]);
        //}
    });
}
  • 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-06T00:03:27+00:00Added an answer on June 6, 2026 at 12:03 am

    If the values in data array are in the same order as they are in the form then you can do this

    insert_data_in_form: function(data) {
        var formElems = $("#dataform input[type='text']");
        formElems.each(function(i,elem) {
            $(this).val(data[i]);
            // or even better use the following faster way 
            // if they are always text boxes
            // this.value = data[i];
        });
    }
    

    Demo: http://jsfiddle.net/joycse06/AJhEW/

    UPDATE (Alternate Way):

    You can also achieve this using Implicit Looping with this .val(function(index,val) variant of the .val() function like this

    var insert_data_in_form =  function(data) {
        var formElems = $("#dataform input[type='text']");
        formElems.val(function(i) {
           return data[i];
        });
    };
    

    Demo: http://jsfiddle.net/joycse06/AJhEW/2/

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

Sidebar

Related Questions

I have an array that has 22 items in it (it may also have
I have a UITableView whose data source is an NSMutableArray. The array contains NSMutableDictionaries
I have been given some 'reports' from another piece of software that contains data
I have an array which has many values in it . I just wanted
I have an array that has keys and values. For eg: Array ( [name]
I have an array which has the contents as the result of an sql
I have an array that has a lot of values including a lot of
Let's say I have an array that has 4 arrays in it. What I
I have created 4 buttons via Interface Builder. I have an array which has
I have a mutable array that has about 100 objects in it and each

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.