Disclaimer: I do not really know how to use jquery (or do many other things).
I have a dropdown menu that populates from a database, and based on the dropdown selection fills a few hidden input fields. After choosing an option in the dropdown, this:
<input class="form-control" type="hidden" name="suporlochtml" id="suporlochtml"/>
changes to...
<input class="form-control" type="hidden" name="suporlochtml" id="suporlochtml" value="local"/>
... which is working as intended.
I want to be able to show or hide a div on the page based on the value of that hidden field. For now, the value could be either "superior" or "local"
After reading this: jQuery - Detect value change on hidden input field I'm under the impression that it requires extra code to detect a change to a hidden input field.
Based on that, here's what I'm trying:
<script>
function setUserID(myValue) {
$('#suporlochtml').val(myValue)
.trigger('change');
}
$('#suporlochtml').change(function(){
if ($('#suporlochtml').val() == "local") {
$("#superiorcourt").hide();
}
else {
$("#superiorcourt").show();
}
});
</script>
I want to show this div when "superior" is the value in the hidden field:
<div class="superiorcourt" id="superiorcourt">
</div>
And I want to show this div when "local" is the value in the hidden field:
<div class="localcourt" id="localcourt">
</div>
Right now nothing happens when the dropdown (and therefore the hidden field value) changes. Both divs are still displayed.
Since I don't really know how to use jquery/javascript, I don't know if it's a syntax error or if this isn't possible. I am able to achieve the desired effect when I detect the change of the dropdown the user controls directly with some code involving this:
$("select").change(function(){
but if I can figure out how to do it with that hidden field value it will save a ton of work.
Any suggestions are appreciated.