Good morning,
I am working on a template for a Django project and I would like to create a dynamic form, and so, according to a result in the drop-down menu, I display different div blocks. So I tried as I knew with a small javascript script but it doesn’t seem to work, the initial drop-down menu hangs on a value, dynamic fields are displayed only once and never disappear or change afterwards.
I guess Django may be the source of the problem.
Am I making a mistake in my code?
Thanks in advance!
<select class="form-select" id="action_menu" onchange="action_disp()">
<option selected>-</option>
<option value="score">score</option>
<option value="color">color</option>
</select>
<script type="text/javascript">
function action_disp(){
var action_menu = document.getElementById('action_menu');
var selected_val = action_menu.options[action_menu.selectedIndex].value;
var score = document.getElementById('score');
var color = document.getElementById('color');
if (selected_val = "score"){
score.style.visibility = 'visible';
color.style.visibility = 'hidden';
}else if(selected_val = "color"){
score.style.visibility = 'hidden';
color.style.visibility = 'visible';
}else{
score.style.visibility = 'hidden';
color.style.visibility = 'hidden';
}
}
action_disp();
</script>
<div id="score" style="visibility:hidden" ></div>
<div id="color" style="visibility:hidden" ></div>