Click to See Complete Forum and Search --> : Preserve Array data, How?
omygod
07-14-2004, 06:02 PM
Hi all,
How do I preserve the data in the array? The addRow function here clears all the value I assigned every time I call it. Thanks for any advice.
myRec = new Array(new Array("", "", "", "", "", "", ""));
// assign value to myRec
function addRow()
{
var i = myRec.length;
myRec[i] = new Array("", "", "", "", "", "", "");
}
steelersfan88
07-14-2004, 06:25 PM
Following a similar code, such as:<script type="text/javascript">
// define array
// 2 dimensions (rows x columns)
var arr = new Array();
// make first element (row) an array
arr[0] = new Array("a1","a2","a3","a4","a5","a6","a7");
function addRow() {
// add new row:
arr[arr.length] = new Array("b1","b2","b3","b4","b5","b6","b7");
}
// cal lthe add row function
addRow();
// write the array to document
// loop thru rows
for(var i=0;i<arr.length;i++) {
// loop thru columns
for(var j=0;j<arr[i].length;j++) {
// write each record
document.write(arr[i][j] + (((j+1)<arr[i].length) ? (", ") : ("")));
}
// go to next row
document.write("<BR>");
}
</script>You'll see the printout will not remove any data. I added comments so you can understand each thing if you need to re-do the code, How are you calling your function?
Dr. Script
omygod
07-15-2004, 10:27 AM
Hi Steelerfan,
Thank for the instruction. I understand your code. I just don't know why my code is not working. Here is my attached code. The problem is after I click the add button to add a row. All the field value I inputed disappear. Please advise. Thanks
steelersfan88
07-15-2004, 11:02 AM
I was able to use the code you provided i nboth IE and Mozilla and experienced no problems of which you claim. All information remains when I add a new row and when I sort the info.
What browser are you using?
omygod
07-15-2004, 11:11 AM
Hi steelersfan88,
I use IE6. I inputed these values into the field:
7/15/2004, TEXU7892564, 12345, 35, 46300, LB
Then I click the add button and the values are gone.
Thanks for any advice.
steelersfan88
07-15-2004, 02:01 PM
IE6. I inputted the same values, clicked add, still there. Clicked sort, went to the bottom.
Do you have this online anywhere?
omygod
07-15-2004, 02:52 PM
Hey, you are right. It works on other computers but not on mine.
This is funny. Thank you.