-1

I know how check if the option is selected and the following condition works but I have to refresh the page to applicate the changes.

Here is my code:

$(function (){
        var select = $("div.form-group:nth-of-type(2)");

        if ($("#id_issue_type option:selected").val() === "other"){
            select.show();
        }

        else {
            select.hide();
        }

    });

The problem is I have to refresh the page and I'd like to applicate the changes directly after I selected the option. My purpose being to hide and show a field depending of the value selected.

Thank you in advance.

Beno
  • 518
  • 1
  • 7
  • 22

1 Answers1

2

you could use change event for drop down, like this:

$( ".target" ).change(function() {
  alert( "Handler for .change() called." );
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form>
  <select class="target">
    <option value="option1" selected="selected">Option 1</option>
    <option value="option2">Option 2</option>
  </select>
</form>