Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

jquery to populate a multi-value form field

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article discusses how to implement server side field validation and display customized error messages to the client.
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

718 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