Conditional Statements in jQuery
<p>I have the jQuery code below and currently it has a <code>Min Rent</code> and <code>Max Rent</code> field. Right now when a value is entered is says <code>$val1 to $0</code> even if a value is not entered in the <code>Max Rent</code> field. What I am trying to accomplish is if a value is entered in both fields for it to say <code>$val1 to $val2</code>. Otherwise I just want it to display the one value. I tried to do this with a conditional statement, but my jQuery is not very strong and not sure where I am going wrong.</p>

<p>jQuery:</p>

<pre><code>$("[data-toggle='popover']").on('shown.bs.popover', function() {
  $("#listing-price-selector").next().find("#listing_search_form_min_price").keyup(modPrice);
  $("#listing-price-selector").next().find("#listing_search_form_max_price").keyup(modPrice);
});

$("[data-toggle='popover']").on('hide.bs.popover', function() {
modPrice();
});
modPrice();

function modPrice() {
  if ($("#listing-price-selector") &amp;&amp; $("#listing-price-selector").next()) {
    var mn = $("#listing-price-selector").next().find("#listing_search_form_min_price").val();
    var mx = $("#listing-price-selector").next().find("#listing_search_form_max_price").val();
    if (mn || mx) {
      mn = (mn == "") ? 0 : mn;
      mx = (mx == "") ? 0 : mx;
      $("#priceBox").val(mn + " to " + mx);
      if ($("#listing_search_form_max_price").length &gt; 0) {
        $("#listing-price-selector").text(" $" + mn + " to $" + mx);
      else
        $("#listing-price-selector").text(" $" + mn);
      }
    }
  }
}
</code></pre>

<p>HTML:</p>

<pre><code>&lt;div class="col-md-2 col-xs-6"&gt;
    &lt;a tabindex="0" class="button btn-transparent" id="listing-price-selector" role="button" data-toggle="popover"&gt;Price Range &lt;span class="caret"&gt;&lt;/span&gt;&lt;/a&gt;
&lt;/div&gt;

&lt;div id="listing-price-content" style="display: none;"&gt;
  &lt;div class="container-fluid"&gt;
    &lt;div class="row"&gt;
      &lt;div class="col-xs-6"&gt;
        &lt;div class="input-group input-group-sm"&gt;
          &lt;span class="input-group-addon" id="basic-addon1"&gt;$&lt;/span&gt;
          &lt;%= f.text_field :min_price, class: "form-control", placeholder: "Min Rent", data: { "binding-name" =&gt; "min-price" } %&gt;
        &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="col-xs-6"&gt;
        &lt;div class="input-group input-group-sm"&gt;
          &lt;span class="input-group-addon" id="basic-addon1"&gt;$&lt;/span&gt;
          &lt;%= f.text_field :max_price, class: "form-control", placeholder: "Max Rent", data: { "binding-name" =&gt; "max-price" } %&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
</code></pre>

<p></p>