3
Could someone give me a north on how to display a vertical menu when the first items select
is selected, I’m doing it in a very crude way, as they will notice that I put margin-top
to move the element up the first element, since they are stacked.
<script type="text/javascript">
function optionCheck(){
var opcaoModSelecionada = document.getElementById("tipoModalidadeEnsino").value;
if(opcaoModSelecionada == "gra"){
document.getElementById("primary-list-course").style.visibility = "visible";
document.getElementById("secundary-list-course").style.visibility = "hidden";
document.getElementById("third-list-course").style.visibility = "hidden";
} else if (opcaoModSelecionada == "pgr"){
document.getElementById("secundary-list-course").style.visibility = "visible";
document.getElementById("primary-list-course").style.visibility = "hidden";
document.getElementById("third-list-course").style.visibility = "hidden";
} else if (opcaoModSelecionada == "ext"){
document.getElementById("third-list-course").style.visibility = "visible";
document.getElementById("primary-list-course").style.visibility = "hidden";
document.getElementById("secundary-list-course").style.visibility = "hidden";
}
}
</script>
@import url('https://fonts.googleapis.com/css?family=Poppins&display=swap');
body {
margin: 0;
padding: 0;
font-family: 'Poppins', sans-serif;
}
.container {
margin: 0 auto;
text-align: center;
width: 40%;
height: auto;
background-color: #ddd;
}
.course {
margin: 0 auto;
text-align: center;
width: 40%;
height: auto;
background-color: bisque;
visibility: hidden;
}
.secundary-list-course {
margin-top: -25px;
}
.third-list-course {
margin-top: -25px;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width-device-width, initial-scale=1.0"/>
<meta http-equiv="X-UA-Compatible" content="ie=edge"/>
<link rel="stylesheet" href="css/style.css"/>
<title>EXIBIÇÃO POR CAMPO SELECIONADO</title>
</head>
<body>
<div class="container">
<label for="tipModalidadeEnsino">Selecione a Modalidade</label>
<select id="tipoModalidadeEnsino" name="tipoModalidadeEnsino" onchange="optionCheck()">
<option value="0" selected>-- Selecione uma das opções --</option>
<option value="gra">Graduação</option>
<option value="pgr">Pós-graduação</option>
<option value="ext">Extensão</option>
</select>
</div>
<div class="primary-list-course course" id="primary-list-course">
<label for="tipoCurso1"><span style="color:blueviolet">Cursos de Graduação</span></label>
<select id="tipoCurso1" name="tipoCurso1">
<option selected>-- Escolha o curso --</option>
<option>Administração</option>
<option>Direito</option>
<option>Ciencias Biológica</option>
<option>Sistemas de Informação</option>
</select>
</div>
<div class="secundary-list-course course" id="secundary-list-course">
<label for="tipoCurso2"><span style="color: blueviolet">Cursos de Pós-graduação</span></label>
<select id="tipoCurso2" name="tipoCurso2">
<option selected>-- Escolha o curso --</option>
<option>Engenharia de Software</option>
<option>Cyber Security</option>
<option>Física</option>
<option>Psicologia</option>
</select>
</div>
<div class="third-list-course course" id="third-list-course">
<label for="tipoCurso3"><span style="color: blueviolet">Cursos de Extensão</</label>
<select id="tipoCurso3" name="tipoCurso3">
<option selected>-- Escolha o curso --</option>
<option>Inglês</option>
<option>Mecatrônica</option>
<option>SegInfo</option>
</select>
</div>
</body>
</html>
Exactly what did you need, but what would xmargin-top be? I would edit my answer because I was giving Uncaught Referenceerror: Function is not defined, I see you fixed that too in your reply. What have you done?
– Lucas Inácio
xmargin-top
It’s typo, it’s justmargin-top
.– Bruno Romualdo
@Lucasinácio It’s because I forgot to delete where it has xmargin-top... The error in the snippet was because you put the tags
<script type="text/javascript">
within the Javascript code.– Sam
Right, but I’m trying to load this script and it’s not going (I’m clicking above the body tag closure), but it triggers the same error..
– Lucas Inácio
@I changed the answer. Take a look.
– Sam
I saw here, just one more question, I noticed that your select was below the label, but you didn’t use hr or anything, so what you did?
– Lucas Inácio
@Lucasinácio I didn’t do anything. The select goes under the label when the screen is small mt. Run the above snippet in full screen and select will be next to the label.
– Sam