I need to pass a value to a textbox but this textbox can't be writable directly by the user. I'm calculating the value using jason:
<script type="text/javascript">
$(document).ready(function () {
$("#txtid").change(function () {
$.ajax({
url: '/CommissionsFinals/GetTarifa',
type: 'GET',
contentType: "application/json; charset=utf-8",
dataType: 'json',
data: { clientID: $("#DDLCliente").val(), consultorID: $("#DDLConsultor").val() },
success: function (tarifa) {
//response(tarifa.
$('#txtid').val(tarifa).autocomplete
},
error: function () {
alert('Error!');
}
});
})
});
The textbox changes his value when i try to input a diferente value. The value is being calculated by the 2 parameters (clientId,consultorId) which are selected in 2 diferente DropDownLists. How do I get the value automatically after selecting those 2 values from the DropDownList?
<th>
@Html.DropDownListFor(m =>m.ManagerId, new SelectList(ViewBag.Manager, "ManagerId", "NomeCompleto"), "Seleccione o Manager", new { @class = "form-control", @id = "DDLManager" })
</th>
<th>
@Html.Label("Consultor", htmlAttributes: new { @class = "control-label col-md-2" })
</th>
<th>
@Html.DropDownListFor(m => m.ConsultorId, new SelectList(ViewBag.Consultor, "ConsultorId", "NomeCompleto"), "Seleccione o Consultor", new { @class = "form-control", @id = "DDLConsultor" })
</th>
GetTarifa
do and what does it return? (the code you have shown will give you errors in the browser console). And what do you mean by "but this textbox can't be writable directly by the user"? It is editable because you have not made it readonly. – user3559349 Nov 16 '15 at 11:05TarifaId
to be editable by the user, then it should be readonly, and you need to handle the.change()
event of the dropdownlists to call the server method (or have a 'calculate' button and handle its.click()
event to call the method). – user3559349 Nov 16 '15 at 11:33