在页面刷新时保留基于选择框的值

I have one form where in select box in which I have two options "oui" and "non":

  • When "oui" is selected "hello" is displayed
  • When "non" is selected "not valid" is displayed

My problem is when I refresh page after submitting form, "oui" or "non" is properly selected but not the value based on it like "hello" or "not valid"

here is some code

<p>choose option: <select name="opt" class="slct">
    <option value="0" selected="selected">--</option>
    <option value="oui">Oui</option>
    <option value="non">Non</option>
    </select>
</p>
<div id="oui" class="brandDiv">
  hello
</div>
<div id="non" class="brandDiv">
  not valid
</div>

and the jquery

function showhide() {
$("div.brandDiv").hide();
$("select.slct").bind('change', function() {
    $('div.brandDiv').hide();
    var targetId = $(this).val();
    $('div#' + targetId).show();
});
}

Thank you all in advance.

What about adding, the following ?

$( function() {
    $("select.slct").each(
      function() {
        $('div.brandDiv').hide();
        var targetId = $(this).val();
        $('div#' + targetId).show();
      }
    );
  }
)

can't you just trigger() the change event on dom ready?

$("select.slct").trigger('change');

or

$("select.slct").change();

Or if I understand you correctly you have a function called showhide()

$(function(){  // <-- on dom ready
      showhide(); // <-- run function
});