1
I have this function and need to load the description of the select. In this function I can only load the id, how can I do to in place of x(which is the id) I get 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’d like to play the description on this field:
<textarea asp-for="ContasApagarVM.ContasApagar.Obs" class="form-control" id="demo"></textarea>
That’s why I need the name, plus value. Here is the controller function Load value.
[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
});
}
But the
id
you are using to make the request, right? You would like to make the request by the description?– reisdev
I edited the question, I need the description to throw it in another field.
– Mariana
The description, in this case, would be the text contained in the option of
select
?– reisdev
Yes, I also put the controller function.
– Mariana