javascript - Issue Updating one Html.TextBoxFor based on value of another -
i'm trying use simple jquery change text of 1 textbox half of numeric value of textbox's text.
my script:
<script> $(document).ready(function () { $('#inventoryvalue').keyup(function () { var stringvalue = $(this).text; var floatvalue = (parsefloat(stringvalue).tofixed(2)) / 2; $('#fiftypercentmultiplier').text(floatvalue); }); }); </script>
my textboxes defined so:
<tr> <td> <b>@html.labelfor(model => model.inventoryvalue, new { @class = "control-label col-md-2" })</b> </td> <td> @html.textboxfor(model => model.inventoryvalue, new { id = "inventoryvalue" }) @html.validationmessagefor(model => model.inventoryvalue) </td> </tr> <tr> <td> <b>@html.labelfor(model => model.fiftypercentmultiplier, new { @class = "control-label col-md-2" })</b> </td> <td> @html.textboxfor(model => model.fiftypercentmultiplier, new { id = "fiftypercentmultiplier" }) @html.validationmessagefor(model => model.fiftypercentmultiplier) </td> </tr>
rendered textboxes:
<input data-val="true" data-val-number="the field *competitive inventory value: must number." id="inventoryvalue" name="inventoryvalue" type="text" value="" /> <input data-val="true" data-val-number="the field *50% (.50) multiplier: must number." id="fiftypercentmultiplier" name="fiftypercentmultiplier" type="text" value="" />
thank in advance help. i've spent last 2 hours @ work smashing head on this!
use .val()
instead of .text()
.
$('#fiftypercentmultiplier').val(floatvalue);
Comments
Post a Comment