Solved

jquery to populate a multi-value form field

Posted on 2013-10-23
4
518 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Suggested Solutions

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…
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

734 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