S
spazzwig
Hi all,
I have a simple js script to show/hide divs for a tabbed interface. It works
well, but now I'm trying to use it with many multiple instances and hoped
that I could use regexp with it to make it more flexible and lighter in
code.
This is what I have, though it keeps returning an "object required" error (I
assume because it's not matching anything):
function changePopTab (tabname) {
var reg=/\d{2}?/; // the digits are for a day of the month eg 15
= 15th. The "?" is to account for multiple instances of the same date (15a,
15b, ...)
document.getElementById('tab_overview'+reg).style.display = 'none';
document.getElementById('tab_resources'+reg).style.display =
'none';
document.getElementById('tab_'+tabname).style.display = 'block';
}
and for example in the body:
<a ... onclick="changePopTab('overview01');return false; ...></a>
<div id="tab_overview01"...></div>
I guess what I'm trying to do is centralize the js function so that I can
use it with many tab instances (tab_overview01, tab_overview02,
tab_overview03, ...etc) without haveing to declare each ID in the function.
Hope this makes sense, I'm very new at js so any suggestions or alternate
approaches are most welcome.
TIA,
Gabe
|N|O|S|P|A|M| -- onlineq (a t) azonis (d o t) com
ps. I tried using getElementsBySelector and using a css .class instead of a
regexp, but didn't seem to fly (method unknown). Regexp does work with
getElementById I hope?
I have a simple js script to show/hide divs for a tabbed interface. It works
well, but now I'm trying to use it with many multiple instances and hoped
that I could use regexp with it to make it more flexible and lighter in
code.
This is what I have, though it keeps returning an "object required" error (I
assume because it's not matching anything):
function changePopTab (tabname) {
var reg=/\d{2}?/; // the digits are for a day of the month eg 15
= 15th. The "?" is to account for multiple instances of the same date (15a,
15b, ...)
document.getElementById('tab_overview'+reg).style.display = 'none';
document.getElementById('tab_resources'+reg).style.display =
'none';
document.getElementById('tab_'+tabname).style.display = 'block';
}
and for example in the body:
<a ... onclick="changePopTab('overview01');return false; ...></a>
<div id="tab_overview01"...></div>
I guess what I'm trying to do is centralize the js function so that I can
use it with many tab instances (tab_overview01, tab_overview02,
tab_overview03, ...etc) without haveing to declare each ID in the function.
Hope this makes sense, I'm very new at js so any suggestions or alternate
approaches are most welcome.
TIA,
Gabe
|N|O|S|P|A|M| -- onlineq (a t) azonis (d o t) com
ps. I tried using getElementsBySelector and using a css .class instead of a
regexp, but didn't seem to fly (method unknown). Regexp does work with
getElementById I hope?