How to get an array of table data into multiple text box elements | Member | | Join Date: Mar 2007
Posts: 33
| |
Hi all,
I have trouble getting an array of data stored in a separate javascript file i.e. a file called books.js into a table of data for a .xhtml file.
There are 50 Records in this file.
There are 5 colums of data I wish to display.
I want to display these records in groups of 10.
Based on the fact that the records I want are located in a separate file, how can I get these details to show on the form and manipulate the data to show in groups of 10?
I know the following code is far from complete but I hope it will explain further what I mean.
Thanks
Jonnie |  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | re: How to get an array of table data into multiple text box elements
Give the table cells ids such as ProdCode1, Quantity1, UnitPrice1, ... ProdCode2, Quantity2, etc.
Then in your function, set the values using: - document.getElementById('ProdCode'+i).innerHTML = arr[...][0];
etc.
| | Member | | Join Date: Mar 2007
Posts: 33
| | | re: How to get an array of table data into multiple text box elements
Hi guys,
I've tried the above suggestions but it seens i'm still not getting any luck getting the details from the file into my form. Below is the data I want to put into my input text boxes. If I have to i'll just put in 5 colums of 50 text boxes but i'd like to do it in groups of 10. -
-
anthologies=new Array();
-
anthologies[0]=new Array("HWS015","Evening",55.59);
-
anthologies[1]=new Array("HWS029","Georgian Romances",19.80);
-
anthologies[2]=new Array("HWS045","The Dark Ages",23.18);
-
anthologies[3]=new Array("HWS057","Elfen Folk",57.75);
-
anthologies[4]=new Array("HWS074","Televised Poetry",13.15);
-
anthologies[5]=new Array("HWS103","Spring",54.39);
-
anthologies[6]=new Array("HWS110","Gardens by moonlight",17.46);
-
anthologies[7]=new Array("HWS130","Rambling Reminiscences",31.62);
-
anthologies[8]=new Array("HWS149","Flight",33.31);
-
anthologies[9]=new Array("HWS166","Ocean View",14.00);
-
etc.. etc. etc.
-
Above this is a file, book.js.
In this file is an array.
There are 5 colums of data.
The data is for 3 columns. The other columns will be set by me as I calculate the raw data.
What I'm really missing is the JavaScript picking up the data in these input boxes so I can then calculate them. Obviously i'll need to remove some of the readonly elements later when i want to make calculations, I just need some wisdom on what I am missing when it comes to actually displaying the data in the array.
Thanks in advance, all.
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | re: How to get an array of table data into multiple text box elements
First of all, set the ids to the textboxes instead of the tds (table cells). Then you can use "value" instead of innerHTML.
You can replace the 50 or so repeated lines (22-87) by just 5-6 lines using a loop: -
-
for (i = 0; i < 10; i++) {
-
document.getElementById('prodCode'+i).value = anthologies[topofpage+i][0];
-
document.getElementById('bookTitle'+i).value = anthologies[topofpage+i][1];
-
document.getElementById('author'+i).value = anthologies[topofpage+i][2];
-
document.getElementById('qty'+i).value = something;
-
document.getElementById('unitP'+i).value = something;
-
}
-
Also, get id of the src attribute for the script tag. Make sure the function is defined properly: - function (args) {
-
...//function body
-
}
-
|  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,471 network members.
|