Show/hide multiple divs

Hi,
I've got most of the code I need, but missing someand hoping someone may be able to help me. I've got 2 checkboxes, AAA and BBB. When I tick checkbox AAA, I'd like the 3 related divs to be displayed, divs called diva-1, diva-2, diva-3. It's the same with checkbox BBB.

All I have at the moment, is when you click checkbox AAA, then the first div is displayed. I know why, because I'm referencing the div, but not referencing the other 2 divs.

So rather than display diva-1, I'd like someone to help me amend the code so it displays all divs that start "diva" - diva-1, diva-2, diva-3 etc.

Here's the code I have.
-----------------------
<script type="text/javascript">
function showMe (it, box) {
var vis = (box.checked) ? "block" : "none";
document.getElementById(it).style.display = vis;
}
</script>

AAA: <input type="checkbox" value="1" name="chkAAA" onclick="showMe('diva-1', this)">
BBB: <input type="checkbox" value="1" name="chkAAA" onclick="showMe('divb-1', this)">
<br><hr><br>

<div id="diva-1" style="display:none;">
test AAA-1
</div>
<div id="divb-1" style="display:none;">
test BBB-1
</div>

<div id="diva-2" style="display:none;">
test AAA-2
</div>
<div id="divb-2" style="display:none;">
test BBB-2
</div>

<div id="diva-3" style="display:none;">
test AAA-3
</div>
<div id="divb-3" style="display:none;">
test BBB-3
</div>
-----------------------

Thanks.
dj_humpygAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TimYatesCommented:
<script type="text/javascript">
function showMe (it, box) {
    var vis = (box.checked) ? "block" : "none";
    var i = 1 ;
    var aDiv = document.getElementById( it + '-' + i ) ;
    while( aDiv )
    {
        aDiv.style.display = vis;
        // Try to ge the next div
        i++ ;
        aDiv = document.getElementById( it + '-' + i ) ;
    }
}
</script>

AAA: <input type="checkbox" value="1" name="chkAAA" onclick="showMe('diva', this)">
BBB: <input type="checkbox" value="1" name="chkAAA" onclick="showMe('divb', this)">
<br><hr><br>

<div id="diva-1" style="display:none;">
test AAA-1
</div>
<div id="divb-1" style="display:none;">
test BBB-1
</div>

<div id="diva-2" style="display:none;">
test AAA-2
</div>
<div id="divb-2" style="display:none;">
test BBB-2
</div>

<div id="diva-3" style="display:none;">
test AAA-3
</div>
<div id="divb-3" style="display:none;">
test BBB-3
</div>

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dj_humpygAuthor Commented:
Extremely fast response, and it works perfectly.

Many thanks :)
TimYatesCommented:
No worries :-)  Glad I could help :-)

Good luck with it :-)

Tim
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.