I have this function and need to load the same description as select. In this function I can just load the id, how can I do it in place of the x (what is the id) I take the description?
function myFunction() {
var x = document.getElementById("mySelect").value;
document.getElementById("demo").innerHTML = "You selected: " + x;
var url = "/ContaApagar/CarregaValor";
$.ajax({
url: url
, data: { id: x }
, type: "POST"
, datatype: "html"
, success: function (data) {
if (data.resultado > 0) {
$("#txtValor").val(data.valor);
}
}
});
}
I would like to play the description in this field:
<textarea asp-for="ContasApagarVM.ContasApagar.Obs" class="form-control" id="demo"></textarea>
That's why I need the name, besides the value. Here is the function of the LoadValue controller.
[HttpPost]
public ActionResult CarregaValor( int id, decimal valor)
{
var item = _context.Receitas.Where( r => r.Id == id && r.Tipo == "D").First();
return Json(new
{
valor = item.Valor
// var teste = valor
});
}