First Last

First Last

  • NA
  • 648
  • 72.4k

JavaScript is not playing nice with boolean false

Aug 19 2020 9:27 PM
Asp.net mvc / jQuery / JavaScript
 
In my partial view, I have a model that has boolean properties that I will pass to JavaScript functions.
 
 
I pass the model boolean properties to JavaScript functions as such.
  1. @model GbngWebClient.Models.LikeOrDislikeVM    
  2.     
  3. <style>    
  4. .fa {    
  5.     cursor: pointer;    
  6.     user-select: none;    
  7. }    
  8.     
  9.     .fa:hover {    
  10.         color: blue;    
  11.     }    
  12.     
  13. /* I added. */    
  14. .my-size {    
  15.     font-size: 20px;    
  16. }    
  17. </style>    
  18.     
  19. @* Use the values that were passed via a model. *@    
  20. <div class="row">    
  21. <p><span class="blogLike my-size fa fa-thumbs-up"></span><span class="my-size"> : @Model.LikeCount</span> <span class="my-size"> | </span><span class="blogDisLike my-size fa fa-thumbs-down"></span><span class="my-size"> : @Model.DisLikeCount</span></p>    
  22. </div>    
  23.     
  24. @Scripts.Render("~/bundles/jquery")    
  25.     
  26. <script type="text/javascript">    
  27. $(document).ready(function () {    
  28.     console.log('Here at document ready');    
  29.     console.log('@Model.LikeDisabled');    
  30.     console.log('@Model.DisLikeDisabled');    
  31.     
  32.     SetLike('@Model.LikeDisabled');    
  33.     SetDisLike('@Model.DisLikeDisabled');    
  34.     
  35.     function SetLike(disabledSwitch) {    
  36.         console.log('Here at SetLike');    
  37.         console.log('disabledSwitch ' + disabledSwitch);    
  38.     
  39.         $(".blogLike").attr('disabled', disabledSwitch);    
  40.     
  41.         if (disabledSwitch == false )    
  42.         {    
  43.             console.log('True');    
  44.             $(".blogLike").color('green');    
  45.         }    
  46.     }    
  47.     
  48.     function SetDisLike(disabledSwitch) {    
  49.         console.log('Here at SetDisLike');    
  50.         console.log('disabledSwitch ' + disabledSwitch);    
  51.     
  52.         $(".blogDisLike").attr('disabled', disabledSwitch);    
  53.     
  54.         if (disabledSwitch == false)    
  55.         {    
  56.             console.log('True');    
  57.             $(".blogDisLike").color('green');    
  58.         }    
  59.     }    
  60. });    
  61. </script>  
The code executes but the boolean values are False instead of false. Yet the model screenshot above shows them as false.
 
JavaScript needs them to be false. Why is this happening and how to fix?
 
 

Answers (3)