Hi,
could anyone help with this simple javascript ?
I habe a webpage which displays several reports.
To avoid mass table rows on opening the page I hide the table rows and only show the headers with a button "show table entries".
This works fine for 3 tables.
This is the script:
<script type="text/javascript">
var rowVisible1 = false;
var rowVisible2 = false;
function toggleDisplay(tbl, no) {
var rowVisible;
if(no == '1'){
rowVisible = rowVisible1;
}
if(no == '2'){
rowVisible = rowVisible2;
}
var table = document.getElementById(tbl);
var tblRows = table.rows;
for (i = 0; i < tblRows.length; i++) {
tblRows.style.display = (rowVisible) ? "none" : "";
}
if(no == '1'){
rowVisible1 = !rowVisible1;
}
if(no == '2'){
rowVisible2 = !rowVisible2;
}
}
</script>
I had to make the 2 variables (rowsVisibleXY), because I had the problem, that when I opened the first table and then when i clicked on the second button to show also the second table I always had to click twice to show it. So this script had a problem to recognize which table is already shown or not etc. and I think that the script thought that it should not open the second table because the first could be openend etc...
So, my question is, HOW can I dynamically generate these rowVisible variables ?
So, I would then pass the number of the table (like I did it currently with 1 or 2) to the script and the script should dynamically create such a variable "rowVisible"+number. And then I would get rid of thes two "if" blocks and I would make a for loop.
Know what I mean ?
cheers
sammes
could anyone help with this simple javascript ?
I habe a webpage which displays several reports.
To avoid mass table rows on opening the page I hide the table rows and only show the headers with a button "show table entries".
This works fine for 3 tables.
This is the script:
<script type="text/javascript">
var rowVisible1 = false;
var rowVisible2 = false;
function toggleDisplay(tbl, no) {
var rowVisible;
if(no == '1'){
rowVisible = rowVisible1;
}
if(no == '2'){
rowVisible = rowVisible2;
}
var table = document.getElementById(tbl);
var tblRows = table.rows;
for (i = 0; i < tblRows.length; i++) {
tblRows.style.display = (rowVisible) ? "none" : "";
}
if(no == '1'){
rowVisible1 = !rowVisible1;
}
if(no == '2'){
rowVisible2 = !rowVisible2;
}
}
</script>
I had to make the 2 variables (rowsVisibleXY), because I had the problem, that when I opened the first table and then when i clicked on the second button to show also the second table I always had to click twice to show it. So this script had a problem to recognize which table is already shown or not etc. and I think that the script thought that it should not open the second table because the first could be openend etc...
So, my question is, HOW can I dynamically generate these rowVisible variables ?
So, I would then pass the number of the table (like I did it currently with 1 or 2) to the script and the script should dynamically create such a variable "rowVisible"+number. And then I would get rid of thes two "if" blocks and I would make a for loop.
Know what I mean ?
cheers
sammes