Hey guys i need some code that will split an array that holds a string which is an item and amount with the delimiter being the (:). (eg. Gas:30 ) loading the elements from the transArray into the values of hmtl texboxes for the item and amount fields Please don't be to harsh with the comments this is my first language for a type-language. Any help is appreciated!
var load = function ()
{
mySetArray(); //Fills the transArray randomly with 1-4 items
var item = '';
var amount = '';
for ( i=1; i<=transArray.length; i++)
{
item = 'item' + i;
amount = 'amount' + i;
transArray.split(":");
}
}
var mySetArray = function ()
{
var myRandom = Math.floor((Math.random() * 100) / 25) + 1; //a number between 1 and 4
transArray = new Array(); //Resets the Array to empty
if (myRandom == 1)
{
transArray[0] = "Food:200";
}
if (myRandom == 2)
{
transArray[0] = "Food:200";
transArray[1] = "Toys:700";
}
if (myRandom == 3)
{
transArray[0] = "Food:200";
transArray[1] = "Toys:700";
transArray[2] = "Mortgage:1800";
}
if (myRandom == 4)
{
transArray[0] = "Food:200";
transArray[1] = "Toys:700";
transArray[2] = "Mortgage:1800";
transArray[3] = "Cable:130";
}
}
window.onload = function ()
{
$("load").onclick = load;
}
spliting complete transArray
instead ofsplitting its elements (strings) one by one
. Also i think yourmySetArray() is not returning your transArray to load function
. I have tried to supply full answer with demo. – Sami Oct 17 at 6:31