Alternate visibility groups are surrounded by same container.
By switching the ID of container, internal CSS will be adjusted showing only one block per container ID.
This container ID has unique value for each child group.
Aqua
Fuchsia
Lime
Aqua First to choose
Fuchsia Second to choose
Lime Third to choose
(will be performed in window onload)
Preserving of state could be done either on server side by initially choosing last used container ID from persisted state(like cookies)
or on client side using cookies:
CssSwitch.html source
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><head><title>CSS switch UI blocks visibility</title></head><bodyonload="RestoreSelection()"><h2>CSS switch UI blocks visibility</h2>
Alternate visibility groups are surrounded by same container.
By switching the ID of container, internal CSS will be adjusted showing only one block per container ID.
This container ID has unique value for each child group.
<br/><inputtype="radio"name="visibility"onclick="ChooseFirstId('Choise1_of_1_2_3','Choise2_of_1_2_3','Choise3_of_1_2_3')"/>Aqua <br/><inputtype="radio"name="visibility"onclick="ChooseFirstId('Choise2_of_1_2_3','Choise1_of_1_2_3','Choise3_of_1_2_3')"/>Fuchsia <br/><inputtype="radio"name="visibility"onclick="ChooseFirstId('Choise3_of_1_2_3','Choise1_of_1_2_3','Choise2_of_1_2_3')"/>Lime <br/><style>
#Choise1_of_1_2_3 #Group1{ display:block}
#Choise1_of_1_2_3 #Group2{ display:none}
#Choise1_of_1_2_3 #Group3{ display:none}
#Choise2_of_1_2_3 #Group1{ display:none}
#Choise2_of_1_2_3 #Group2{ display:block}
#Choise2_of_1_2_3 #Group3{ display:none}
#Choise3_of_1_2_3 #Group1{ display:none}
#Choise3_of_1_2_3 #Group2{ display:none}
#Choise3_of_1_2_3 #Group3{ display:block}
</style><divid="Choise1_of_1_2_3"><divid="Group1"style="background-color:Aqua">Aqua First to choose</div><divid="Group2"style="background-color:Fuchsia">Fuchsia Second to choose</div><divid="Group3"style="background-color:Lime">Lime Third to choose</div></div><buttononclick="RestoreSelection()">Restore Selection</button>(will be performed in window onload)<br/>
Preserving of state could be done either on server side by initially choosing last used container ID from persisted state(like cookies)<br/>
or on client side using cookies:
<scripttype="text/javascript">function ChooseFirstId( idToSet, id_1, id_2)
{
for( var i = 0; i< arguments.length; i++ )
{ var el = document.getElementById(arguments[i]);
if( el )
el.setAttribute("id",idToSet);
}
// storelastchoise
createCookie("LastSelection",idToSet);
}
function RestoreSelection()
{
var lastId = readCookie("LastSelection");
if( !lastId )
lastId = "Choise1_of_1_2_3";
ChooseFirstId(lastId,'Choise1_of_1_2_3','Choise2_of_1_2_3','Choise3_of_1_2_3');
var radios = document.getElementsByName("visibility");
if( lastId == "Choise1_of_1_2_3" ) radios[0].checked = true;
if( lastId == "Choise2_of_1_2_3" ) radios[1].checked = true;
if( lastId == "Choise3_of_1_2_3" ) radios[2].checked = true;
}
// cookiesbyhttp://www.quirksmode.org/js/cookies.htmlfunction createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
elsevar expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)=='') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
returnnull;
}
function eraseCookie(name) {
createCookie(name,"",-1);
}
</script></body></html>
BSD type licence.
Copyright (c) 2008, Sasha Firsov, Simulation Works, LLC
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Simulation Works, LLC nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.