jquery - When I pick default dropdown value with javascript, it doesn't trigger change -


i have textfield , date textfield. trying connect them javascript, encounter problem. script is:

         <script>             $("#soldate").change(function () {                 if ($(this).val().trim() == '') {                     $("#casestatus").val('in progress');                     $("#solvedby").val('pick option');                     $("#solvedby").change();                 }                 else if ($(this).val().trim() != '' && $("#solvedby").val().trim() == '') {                     $("#casestatus").val('solved');                     $("#solvedby").val('please, pick issue solver');                     $("#solvedby").change();                 }             });         </script> 

when date picked calendar, should set value 'please, pick issue solver'. works perfectly.

then, if entered date incidentally, should return previous default value - "pick option".

in both cases, change triggered.

then, trigger listening these changes.

<script>         $("#solvedby").change(function () {             if ($(this).val() == 'please, pick issue solver') {                 $("#savebtn").attr('disabled', true);                 $("#slvbyvalmsg").text('you have solution date , no solver');             }             else if ($(this).val().trim() == '' && $("#soldate").val().trim() != '') {                 $("#savebtn").attr('disabled', true);                 $("#slvbyvalmsg").text('you have solution date , no solver');             }             else {                 $("#savebtn").attr('disabled', false);                 $("#slvbyvalmsg").text('');;             }         });     </script> 

after troubleshooting, turns out, first if statement on first script doesn't trigger change. may because doesn't recognize default pick option value ''. not sure. anyhow, when delete date textfield, value of other textfield doesn't change 'pick option', ''.

html code:

 @html.labelfor(model => model.solution_date, htmlattributes: new { @class = "control-label col-md-2" })<sup> 1 </sup>  <div class="col-md-10">       @html.textboxfor(model => model.solution_date, new { @id = "soldate", @class = "one", @type = "datetime" })       <br />       @html.validationmessagefor(model => model.solution_date, "", new { @class = "text-danger" })  </div>   @html.labelfor(model => model.solved_by, htmlattributes: new { @class = "control-label col-md-2" }) <div class="dropdown">      @html.dropdownlistfor(model => model.solved_by, (ienumerable<selectlistitem>)viewbag.slvby, "pick option", new { @id = "solvedby" }) <br /> @html.validationmessage("solved_by", "", new { @id = "slvbyvalmsg", @class = "text-danger" }) </div> 

i know there better ways this, i'm looking resolution because don't know why change trigger doesn't fire.

thanks in advance!

i've found causes issue. turns out

$("#solvedby").val('pick option'); 

cannot executed, because default option , value behind ''. must messing .change() triggers , created havoc in other scripts well.

i changed

$("#solvedby").val(''); 

...and works now.


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

mapreduce - Resource manager does not transit to active state from standby -

serialization - Convert Any type in scala to Array[Byte] and back -