Solved

jquery to populate a multi-value form field

Posted on 2013-10-23
4
500 Views
Last Modified: 2013-10-24
I have a field that I want to populate using jquery

$('#stock_0').html(data).... works perfectly

$('#stock_0[]').html(data)...   how would I populate this field  (add value to the array?)
0
Comment
Question by:joomla
  • 2
4 Comments
 
LVL 14

Accepted Solution

by:
Pierre Cornelius earned 100 total points
ID: 39596419
This
$('#stock_0').html(data)
just puts whatever is in data as the innerHTML for $('#stock_0')

It is not an array, so not sure what you mean. But if you wanted to add more to the $('#stock_0') you can do this:
$('#stock_0').append(moredata);
0
 
LVL 22

Expert Comment

by:Mrunal
ID: 39596431
Hi
Generally arrays in JavaScript are defined like:

var fruits = ["Apple", "Orange", "Donkey"]

So there is no need to add [] next to "stock_0"

Another option:

var arrayContents = new Array();

Now check what value you are getting in data.

You can add values in this array directly by assigning data value to this varibale OR
you can add loop and push items in this variable like:

for loop starts ---
            arrayContents.push(itemshere);
for loop ends


Hope this helps you.
0
 

Author Closing Comment

by:joomla
ID: 39596446
thanks that's the direction I wanted to go
0
 
LVL 14

Expert Comment

by:Pierre Cornelius
ID: 39596455
You're welcome.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now