hello, i have been asked to generate javascript code that will allow a user to keep track of stock. the user will in a form enter:
stock price,description,stick code. then the user should be able to change the stock price of any item and then display the changed price together with the other items.
e.g
Stock Code c101
Description white shoe
Price 150
[add button] clears the filed for the user to enter more
stock code c101
Price 120
[update button]
then the new list with the updated price should be displayed.
I am thinking of using an array to store the information but I do not know how to access each element in the array for editing and storing all the items that the user will enter. I came across "array of objects" though so maybe i can use that too??
Plz help, thanks
Loading
VulpesRank #55 · 29.2K reputationPosted May 26, 2011, 7:36 AM EDT
VulpesRank #55 · 29.2K reputationPosted May 15, 2011, 2:03 AM EDT
This sample code may help:
Sam HobbsRank #107 · 20.5K reputationPosted May 15, 2011, 1:37 PM EDT
You have at least three options for storing the data on disk. The array of objects is, as far as I understand, a way to have the data in memory but they don't exist on disk, correct?
You can store the data on disk in a file such as a comma-separated-value (CSV) format or another delimited format using a delimiter such as tabs.
Another very common format is XML. There is extensive support for XML in JavaScript.
Another option is a database. This is a very common and practical solution. You can use either SQL Server or MySQL but there are other possibilities.
Avuya MxoliRank #7,940 · 231 reputationPosted May 16, 2011, 11:27 AM EDT
Avuya MxoliRank #7,940 · 231 reputationPosted May 16, 2011, 11:29 AM EDT
Sam HobbsRank #107 · 20.5K reputationPosted May 16, 2011, 5:59 PM EDT
JavaScript also has arrays as Vulpes explained, but they are different from arrays in most languages. What JavaScript calls arrays, most languages would call dictionaries or maps or something else.
Avuya MxoliRank #7,940 · 231 reputationPosted May 18, 2011, 10:15 AM EDT
VulpesRank #55 · 29.2K reputationPosted May 18, 2011, 11:44 AM EDT
// Stock constructor
I'd check out the section on functions in this tutorial (http://www.w3schools.com/js/js_functions.asp).
Avuya MxoliRank #7,940 · 231 reputationPosted May 19, 2011, 8:11 AM EDT
VulpesRank #55 · 29.2K reputationPosted May 19, 2011, 10:00 AM EDT
However, I've just tried the code myself (Google Chrome) and it worked fine.
Can you post the HTML for the form and let me know which browser you're using, please.
Avuya MxoliRank #7,940 · 231 reputationPosted May 19, 2011, 10:18 AM EDT