0

hola comunidad stack necesito ayuda con mi funcion javascript no hace la multiplicacion de campos de texto.

//funcion para multiplicar dos campos de texto
<script type="text/javascript">
    function multiplicar() {
        m1 = document.getElementById("Text1").value;
        m2 = document.getElementById("Text2").value;
        r = m1 * m2;
        document.getElementById("idtot").value = r;
    }
</script>
<div class="editor-label">
    @Html.LabelFor(model => model.qtyot)
</div>
<div class="editor-field">
    @Html.EditorFor(model => model.qtyot, new { @id = "Text1", @onchange = "multiplicar();" })
    @Html.ValidationMessageFor(model => model.qtyot)
 </div>
 <div class="editor-label">
    @Html.LabelFor(model => model.aot)
</div>
<div class="editor-field">
    @Html.EditorFor(model => model.aot, new { @id = "Text2", @onchange = "multiplicar();" })
    @Html.ValidationMessageFor(model => model.aot)
</div>
<div class="editor-label">
    @Html.LabelFor(model => model.tot)
</div>
<div class="editor-field2">
    @Html.EditorFor(model => model.tot, new { @id = "idtot" })
    @Html.ValidationMessageFor(model => model.tot)
</div>

1
  • Que es lo que hace? Haz imprimido el valor de r? Console.log?
    – sioesi
    el 4 nov. 2016 a las 19:51

1 respuesta 1

1

A los EditorFor no se les puede dar atributos html debes declarar

@Html.TextBoxForModel(x => x.qtyot, new { @id = "Text1",  @onchange = "multiplicar();"})

Donde x=> x.qtyot es el modelo de tu EditorFor

2
  • el helper correcto era @html.TextBoxFor, pero me ha funcionado. gracias again.
    – Hlvr
    el 4 nov. 2016 a las 21:07
  • Voy a editarlo! Gracias!
    – sioesi
    el 4 nov. 2016 a las 21:07

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.