Solved

jquery to populate a multi-value form field

Posted on 2013-10-23
4
510 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

777 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