title: JQuery val() throws runtime error when setting form value
body: <p>I'm new to Javascript/JQuery, so apologies if I'm missing something simple.  I'm trying to make a button to calculate the total from a quantity &amp; unit price, and populate the total field with the result.  This is done in ASP.NET MVC3, using VS2010.</p>
  
  <p>My code appears to pull the values of SpoilageQuantity and SpoilageUnitPrice OK, but fails at setting the value of SpoilageTotalPrice.  The error says that I'm trying to assign a value to a function result, but my understanding is that val() can be used to get and set a form field value.  Corrections or suggestions?</p>
  
  <p>VS2010 view:</p>
  
  <pre><code>&lt;div class="editor-label"&gt;
      @Html.LabelFor(model =&gt; model.SpoilageQuantity)
  &lt;/div&gt;
  &lt;div class="editor-field"&gt;
      @Html.EditorFor(model =&gt; model.SpoilageQuantity)
      @Html.ValidationMessageFor(model =&gt; model.SpoilageQuantity)
  &lt;/div&gt;
  
  &lt;div class="editor-label"&gt;
      @Html.LabelFor(model =&gt; model.SpoilageUnitPrice)
  &lt;/div&gt;
  &lt;div class="editor-field"&gt;
      @Html.EditorFor(model =&gt; model.SpoilageUnitPrice)
      @Html.ValidationMessageFor(model =&gt; model.SpoilageUnitPrice)
  &lt;/div&gt;
  
  &lt;div class="editor-label"&gt;
      @Html.LabelFor(model =&gt; model.SpoilageTotalPrice)
  &lt;/div&gt;
  &lt;div class="editor-field"&gt;
      @Html.EditorFor(model =&gt; model.SpoilageTotalPrice)
      @Html.ValidationMessageFor(model =&gt; model.SpoilageTotalPrice)
      &lt;input type="button" value="Calculate" onclick="calculateTotal()" /&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>JS file:</p>
  
  <pre><code>function calculateTotal() {
  // calculate total spoilage price from unit price and quantity
  var totalprice = $('#SpoilageQuantity').val() * $('#SpoilageUnitPrice').val();
  totalprice = totalprice.toFixed(2);
  
  $('#SpoilageTotalPrice').val(totalprice);
  }
  </code></pre>
  
  <p>Rendered HTML:</p>
  
  <pre><code>&lt;div class="editor-label"&gt;
          &lt;label for="SpoilageQuantity"&gt;Item Quantity&lt;/label&gt;
      &lt;/div&gt;
      &lt;div class="editor-field"&gt;
          &lt;input class="text-box single-line" data-val="true" data-val-number="The field Item Quantity must be a number." data-val-required="Quantity of item lost is required." id="SpoilageQuantity" name="SpoilageQuantity" type="text" value="0.00" /&gt;
          &lt;span class="field-validation-valid" data-valmsg-for="SpoilageQuantity" data-valmsg-replace="true"&gt;&lt;/span&gt;
      &lt;/div&gt;
  
      &lt;div class="editor-label"&gt;
          &lt;label for="SpoilageUnitPrice"&gt;Unit Price&lt;/label&gt;
      &lt;/div&gt;
      &lt;div class="editor-field"&gt;
          &lt;input class="text-box single-line" data-val="true" data-val-number="The field Unit Price must be a number." data-val-required="Unit price is required." id="SpoilageUnitPrice" name="SpoilageUnitPrice" type="text" value="0.00" /&gt;
          &lt;span class="field-validation-valid" data-valmsg-for="SpoilageUnitPrice" data-valmsg-replace="true"&gt;&lt;/span&gt;
      &lt;/div&gt;
  
      &lt;div class="editor-label"&gt;
          &lt;label for="SpoilageTotalPrice"&gt;Total Price&lt;/label&gt;
      &lt;/div&gt;
      &lt;div class="editor-field"&gt;
          &lt;input class="text-box single-line" data-val="true" data-val-number="The field Total Price must be a number." data-val-required="The Total Price field is required." id="SpoilageTotalPrice" name="SpoilageTotalPrice" type="text" value="0.00" /&gt;
          &lt;span class="field-validation-valid" data-valmsg-for="SpoilageTotalPrice" data-valmsg-replace="true"&gt;&lt;/span&gt;
          &lt;input type="button" value="Calculate" onclick="calculateTotal()" /&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>Error Message:</p>
  
  <pre><code>Microsoft JScript runtime error: Cannot assign to a function result
  </code></pre>
  
  <p>Edit: Entire js file:</p>
  
  <pre><code>/*  Copyright 2012 Tom Barrett
  
  This file is part of PFC Logs.
  
  PFC Logs is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.
  
  PFC Logs is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
  
  You should have received a copy of the GNU General Public License
  along with PFC Logs.  If not, see &lt;http://www.gnu.org/licenses/&gt;.
  */
  
  function autoFocus() {
      // Auto-focus on the first text field upon page load.
      $("input[type=text]").first().focus();
  }
  
  function calculateTotal() {
      // calculate total from quantity &amp; unit price
      var totalprice = $('#SpoilageQuantity').val() * $('#SpoilageUnitPrice').val();
      totalprice = totalprice.toFixed(2);
      $("#SpoilageTotalPrice").val(totalprice);
  }
  </code></pre>