/    Sign up×
Community /Pin to ProfileBookmark

Show/Hide Tabs based on dropdown value selected

I have tabs built purely based on css. I want to be able to show/hide these tabs based on a dropdown value selected. I was able to do this, but for one thing! If I have 3 tabs and want to show tab 1 & tab 3, how can I make tab3 to take the position of tab2 instead of having an empty space for tab2?
Here’s my code:
<html>
<head>
<title>Untitled</title>
<style type=”text/css”>
body {
margin-left: 15px;
margin-right: 15px;
padding: 0px;
font-family: verdana, Arial, Helvetica, sans-serif;
}
#tabmenu {
color: #CCDAEA;
border-bottom: 2px solid #3A68A1;
margin: 12px 0px 0px 0px;
padding: 0px;
z-index: 1;
padding-left: 15px;
}
#tabmenu li {
display: inline;
overflow: hidden;
list-style-type: none; }

#tabmenu a {
color: #CCDAEA;
background: #3A68A1;
font: bold 0.6em verdana, Arial, sans-serif;
border: 2px solid #3A68A1;
padding: 2px 5px 0px 5px;
margin: 0px;
text-decoration: none; }
#tabmenu a:visited {
color: #CCDAEA; }
#tabmenu a.active {
background: #CCDAEA;
border-bottom: 3px solid #CCDAEA;
color: #3A68A1;
}
#tabmenu a.active:visited {
color: #3A68A1; }
</style>

<script type=”text/javascript”>

function showTab2()
{
var Selbox1 = document.forms[0].tab2; /* This is for loan */
var opt1 = Selbox1.options[Selbox1.selectedIndex].text;
if (opt1 == “Yes”)
{
document.all.t2.style.visibility = “visible”;
}
else
{
document.all.t2.style.visibility = “hidden”;
}
}
function showTab3()
{
var Selbox1 = document.forms[0].tab3;
var opt1 = Selbox1.options[Selbox1.selectedIndex].text;
if (opt1 == “Yes”)
{
document.all.t3.style.visibility = “visible”;
}
else
{
document.all.t3.style.visibility = “hidden”;
}
}
</script>
</head>

<body>
<ul id=”tabmenu”>

<li id=”t1″ style=”visibility:visible”><a href=”#”>Home</a></li>
<li id=”t2″ style=”visibility:hidden”><a href=”#”>Customer</a></li>
<li id=”t3″ style=”visibility:hidden”><a href=”#”>Product</a></li>

</ul>
<form>
Customer: <select name=”tab2″ onChange=”showTab2();”>
<option>Select a value</option>
<option>Yes</option>
<option>No</option>
</select>

Product: <select name=”tab3″ onChange=”showTab3();”>
<option>Select a value</option>
<option>Yes</option>
<option>No</option>
</select>
</form>
</body>
</html>

Here,

  • 1. Select “Yes” form customer dropdown and the customer tab will appear

  • 2. Select “Yes” from product dropdown and the product tab will appear

  • 3. Now select “No” from customer dropdown, I want the product tab to move to its left and take the position of customer tab instead of having an empty space
  • Thanks Much

    to post a comment
    JavaScript

    0Be the first to comment 😎

    ×

    Success!

    Help @mili spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.28,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...