I have a little problem when positioning elements; that is, I want to click on a inputs radio
show me x content according to the value that corresponds. For this I add the same name to all input radio
because I only want to choose an option. Here is the code of what I try to do
var saleType=function (){//funcion para la seleccion
var category =$("input[name=selector]:checked").val();
if (category=="truck") {
alert(category)
$("#truck").show()
}else if(category=="bike"){
alert(category)
$("#bike").show()
}else if(category=="plane"){
alert(category)
$("#plane").show()
}else if(category=="boat"){
alert(category)
$("#boat").show()
}else if(category=="car"){
alert(category)
$("#car").show()
}
}
//ejecutar funcion
$(document).on("click","input[name=selector]",function(){
saleType()
})
.progress-bar {
overflow: hidden;
font-size: 9px;
position: absolute;
display: none;
background:#fff;
width:50%;
height:100px;
}
div{
position:relative;
width:60%;
background:lightgrey;
height:300px;
}
ul{
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!--estos radio al clikear me tienen que mostrar los ul segun el valor-->
<fieldset>
<input type="radio" id="Vehicle" name="selector" value="truck">
<input type="radio" id="Vehicle" name="selector" value="car">
<input type="radio" id="Vehicle" name="selector" value="bike">
<input type="radio" id="Vehicle" name="selector" value="plane">
<input type="radio" id="Vehicle" name="selector" value="boat">
</fieldset>
<br>
<div>
<ul id="truck" class="progress-bar bg-light mt-1 p-4 " >
<h1>truck</h1>
</ul>
<ul id="car" class="progress-bar bg-light mt-1 p-4 " >
<h1>car</h1>
</ul>
<ul id="bike" class="progress-bar bg-light mt-1 p-4 " >
<h1>bike</h1>
</ul>
<ul id="plane" class="progress-bar bg-light mt-1 p-4 " >
<h1>plane</h1>
</ul>
<ul id="boat" class="progress-bar bg-light mt-1 p-4 " >
<h1>boat</h1>
</ul>
</div>
This works half-heartedly, because when I try to re-show the content according to the value it fails me, what I want is that if I click on any of the radio inputs always show me its corresponding content.
EYE: I could do it in the following way and it would work but I want something more efficient and less tedious
if (category=="truck") {
$("#truck").show()
$("#bike").hide()
$("#car").hide()
$("#plane").hide()
$("#boat").hide()
}etc......