Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

jquery to populate a multi-value form field

Posted on 2013-10-23
4
Medium Priority
?
544 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 400 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

876 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