I was able to sum the two fields using Java Script, but the result only displayed when clicking the result field, I would like to display the result automatically, without having to click anything.
Javascript
<script type="text/javascript">
$(document).ready(function ()
{
$('#acontratar, #ch').blur(function ()
{
var acontratar = $('#acontratar').val();
var ch = $('#ch').val();
if (acontratar == "") acontratar = 0;
if (ch == "") ch = 0;
var resultado = parseInt(acontratar) * parseInt(ch);
$('#total').val(resultado);
});
});
View
<div class="ibox-content">
<div class="form-group">
@Html.LabelFor(model => model.Nr_AContratar, new { @class = "control-label col-md-2" })
<div class="col-md-2">
@Html.TextBoxFor(model => model.Nr_AContratar, new { @class = "form-control col-md-1", @id = "acontratar" })
@Html.ValidationMessageFor(model => model.Nr_AContratar)
</div>
@Html.LabelFor(model => model.Nr_CargaHorariaContratar, "Carga Horaria Semanal", new { @class = "control-label col-md-2" })
<div class="col-md-2">
@Html.DropDownListFor(model => model.Nr_CargaHorariaContratar, new SelectList(string.Empty),
"---", new { style = "width: 50px;", @id = "ch" })
@Html.ValidationMessageFor(model => model.Nr_CargaHorariaContratar)
</div>
@Html.LabelFor(model => model.Nr_TotalPlano, new { @class = "control-label col-md-2" })
<div class="col-md-2">
@Html.TextBoxFor(model => model.Nr_TotalPlano, new { @class = "form-control col-md-2", @id = "total" })
@Html.ValidationMessageFor(model => model.Nr_TotalPlano)
</div>
</div>
</div>