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
VulpesPosted May 26, 2011, 11:36 AM
Avuya MxoliPosted May 27, 2011, 5:50 AM
VulpesPosted May 27, 2011, 4:43 AM
However, if you're short of time, a quick solution would be to center align everything including the two initial tables.
Avuya MxoliPosted May 26, 2011, 3:29 PM
Avuya MxoliPosted May 26, 2011, 11:13 AM
function GetAverage()
{
var avg = 0;
var sum = 0;
var table = document.getElementById("dynam");
for(var i = table.rows.length - 2; i >= 0; i--)
{
table.deleteRow(i);
}
table.cellSpacing = "20";
var row, cell;
row = table.insertRow(0);
cell = row.insertCell(0);
cell.appendChild(document.createTextNode("Average"));
cell = row.insertCell(1);
for (var i = 0; i <= arrStock.length; i++)
{
var sum = 0;
var avg = 0;
sum = sum + arrStock[i].price;
avg = (sum / arrStock.length);
row = table.insertRow(i);
cell = row.insertCell(0);
cell.appendChild(document.createTextNode(avg));
cell = row.insertCell(1);
}
}
the idea of the table os the same as that of the refresh button.
Thanx
VulpesPosted May 25, 2011, 11:22 AM
The code for the RefreshList() function will then be:
// delete all rows except button
Avuya MxoliPosted May 25, 2011, 7:56 AM
Stock List
I did the table like this because before the refresh button is pressed the table that I need to create isnt visible so I thot its onli created at the RefreshList() function. So here I need to read the array and put its contents on the table and tht table needs to be appear in btwn the heading(Stock List) and the button(Refresh) like this:
Stock List
Stock Code Description Price
1 A 25.00
2 B 26.00
[Refresh]
after the user updates the price, then presses the refresh button, this time it shud show the new price of that item together with other items ofcoz
thanx
VulpesPosted May 23, 2011, 11:57 AM
function UpdateStock()
{
for(var i = 0; i < arrStock.length; i++)
{
if(arrStock[i].code == document.MyForm.txtCodeUpdate.value)
{
var oldPrice = arrStock[i].price;
arrStock[i].price = document.MyForm.txtPriceUpdate.value;
document.MyForm.txtCodeUpdate.value = "";
document.MyForm.txtPriceUpdate.value = "";
alert("Stock record code " + arrStock[i].code + ", description " + arrStock[i].description + ", price updated from " + oldPrice + " to " + arrStock[i].price);
return;
}
}
}
To do the code for the Refresh button, I'll need to see the HTML for both that button and the table.
Avuya MxoliPosted May 23, 2011, 7:34 AM
eg
stock code: 101
price : 20.00
[update button]
101 jacket 20.00
102 shoes 22.00
103 pants 40.00
[refresh button]
VulpesPosted May 20, 2011, 4:31 AM
Simply Shoes Stock Management
New Stock
Update Stock