Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Where am I going wrong?

I can't seem to figure out how to make this work.
Code:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>     
<script>
    $(document).ready(function(){
        $('#myselection').on('change', function(){
            var demovalue = $(this).val();
            $("div.myDiv").hide();
            $("#show"+demovalue).show();
        });
    });
</script>
<script>
    $(document).ready(function(){
        $('#myselection1').on('change', function(){
            var demovalue = $(this).val();
            $("div.myDiv1").hide();
            $("#show1"+demovalue).show();
        });
    });
</script>
<script>
    $(document).ready(function(){
        $('#myselection2').on('change', function(){
            var demovalue = $(this).val();
            $("div.myDiv2").hide();
            $("#show2"+demovalue).show();
        });
    });
</script>
<script>
    $(document).ready(function(){
        $('#myselection3').on('change', function(){
            var demovalue = $(this).val();
            $("div.myDiv3").hide();
            $("#show3"+demovalue).show();
        });
    });
</script>
<script>
    $(document).ready(function(){
        $('#myselection4').on('change', function(){
            var demovalue = $(this).val();
            $("div.myDiv4").hide();
            $("#show4"+demovalue).show();
        });
    });
</script>
<script>
    $(document).ready(function(){
        $('#myselection5').on('change', function(){
            var demovalue = $(this).val();
            $("div.myDiv5").hide();
            $("#show5"+demovalue).show();
        });
    });
</script>
<select id="myselection">
    <option>Choose program</option>
    <option value="yma">Youth Martial Arts</option>
    <option value="ama">Adult Martial Arts</option>
    <option value="yj">Youth Jedi</option>
    <option value="aj">Adult Jedi</option>
</select>
<div id="showyma" class="myDiv">
    <select id="myselection1">
    <option>Choose rank</option>
    <option value="ywhite">White Belt</option>
    <option value="yyellow">Yellow Belt</option>
    <option value="yadvyellow">Advanced Yellow Belt</option>
</select>
<div id="show1ywhite" class="myDiv1">
    You have selected vehicle <strong>"Bike"</strong>.
</div>
</div>
<div id="showama" class="myDiv2">
    <select id="myselection3">
    <option>Choose rank</option>
    <option value="awhite">White Belt</option>
    <option value="ayellow">Yellow Belt</option>
    <option value="aadvyellow">Advanced Yellow Belt</option>
</select>
<div id="show1awhite" class="myDiv3">
    You have selected vehicle <strong>"Bike"</strong>.
</div>
</div>
<div id="showyj" class="myDiv4">
    <select id="myselection5">
    <option>Choose rank</option>
    <option value="ywhite">White Belt</option>
    <option value="yyellow">Yellow Belt</option>
    <option value="yadvyellow">Advanced Yellow Belt</option>
</select>
<div id="show3ywhite" class="myDiv5">
    You have selected vehicle <strong>"Bike"</strong>.
</div>
</div>
<style>
.myDiv{
    display:none;
    padding:10px;
    margin-top:20px;
} 
.myDiv1{
    display:none;
    padding:10px;
    margin-top:20px;
} 
.myDiv2{
    display:none;
    padding:10px;
    margin-top:20px;
} 
.myDiv3{
    display:none;
    padding:10px;
    margin-top:20px;
} 
.myDiv4{
    display:none;
    padding:10px;
    margin-top:20px;
} 
.myDiv5{
    display:none;
    padding:10px;
    margin-top:20px;
} 
#showyma{
    border:1px solid red;
}
#showama{
    border:1px solid green;
}
#show1ywhite{
    border:1px solid green;
}
#show1awhite{
    border:1px solid green;
}
#show3ywhite{
    border:1px solid green;
}
#showyj{
    border:1px solid blue;
}
#showaj{
    border:1px solid blue;
}
</style>
 
Do you want to show the "Choose rank" select in a box with a border of a unique color?

For starters, you have more than one $(document).ready(function(){...}.

Can I give you the solution with raw JS and not the over-bloated jquery?
 
I changed a few things, but this almost works. One problem - I added the div for adult jedi and this will not work if it is selected first. any other selection and things work.
Code:
<!DOCTYPE html>
<html>
<head>
<title>Table Example</title>
<style>
.myDiv{
    display:none;
    padding:10px;
    margin-top:20px;
}
.myDiv1{
    display:none;
    padding:10px;
    margin-top:20px;
}
.myDiv2{
    display:none;
    padding:10px;
    margin-top:20px;
}
.myDiv3{
    display:none;
    padding:10px;
    margin-top:20px;
}
.myDiv4{
    display:none;
    padding:10px;
    margin-top:20px;
}
.myDiv5{
    display:none;
    padding:10px;
    margin-top:20px;
}
#showyma{
    border:1px solid red;
}
#showama{
    border:1px solid green;
}
#show1ywhite{
    border:1px solid green;
}
#show1awhite{
    border:1px solid green;
}
#show3ywhite{
    border:1px solid green;
}
#showyj{
    border:1px solid blue;
}
#showaj{
    border:3px solid rgb(143, 143, 0);
}
</style>
</head>
<body>
<select id="myselection">
    <option>Choose program</option>
    <option value="yma">Youth Martial Arts</option>
    <option value="ama">Adult Martial Arts</option>
    <option value="yj">Youth Jedi</option>
    <option value="aj">Adult Jedi</option>
</select>

<div id="showyma" class="myDiv">
    <select id="myselection1">
    <option>Choose rank</option>
    <option value="ywhite">White Belt</option>
    <option value="yyellow">Yellow Belt</option>
    <option value="yadvyellow">Advanced Yellow Belt</option>
</select>
<div id="show1ywhite" class="myDiv">
    You have selected vehicle <strong>"Bike"</strong>.
</div>
</div>

<div id="showama" class="myDiv">
    <select id="myselection3">
    <option>Choose rank</option>
    <option value="awhite">White Belt</option>
    <option value="ayellow">Yellow Belt</option>
    <option value="aadvyellow">Advanced Yellow Belt</option>
</select>
<div id="show1awhite" class="myDiv">
    You have selected vehicle <strong>"Bike"</strong>.
</div>
</div>

<div id="showyj" class="myDiv">
    <select id="myselection5">
    <option>Choose rank</option>
    <option value="ywhite">White Belt</option>
    <option value="yyellow">Yellow Belt</option>
    <option value="yadvyellow">Advanced Yellow Belt</option>
</select>
<div id="show3ywhite" class="myDiv">
    You have selected vehicle <strong>"Bike"</strong>.
</div>
</div>

<div id="showaj" class="myDiv" >
    <select id="myselection7">
    <option>Choose rank</option>
    <option value="awhite">White Belt</option>
    <option value="ayellow">Yellow Belt</option>
    <option value="aadvyellow">Advanced Yellow Belt</option>
</select>
<div id="show1awhite" class="myDiv">
    You have selected vehicle <strong>"Bike"</strong>.
</div>
</div>


<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>     
<script>
    $(document).ready(function(){
        $('#myselection').on('change', function(){
            var demovalue = $(this).val();alert(demovalue);
           $("div.myDiv").hide();
            $("#show"+demovalue).show();
        });
    });
</script>
</body>
</html>
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom