Javascript does not calculate when working with @using (Html.BeginForm ("", "", FormMethod.Post))

0

I have a view in which within it I add HTML and Javascript to do mathematical calculations, until then everything works fine, the problem arises from the fact that I use the @using (html.beginform ...) ... then this Javascript stops working, what I want to get is that when I put the HTML inside the @using ... Js stops working.

I mean, what I mean is that the HTML outside the @using the Js works well performing the calculations, but when this same HTML is inside the using the JS does not do the calculations.

I hope someone can know why and can help me, I leave my html attached:

     @*El Js con el Hmtl fuera del using trabaja bien, pero cuando el Htmk está dentro de del using el Js ya no hace los calculos*@

                @using (Html.BeginForm("InsertarRemuneracion", "Remuneracion", FormMethod.Post))
                {
                    <h5><strong>INGRESOS Y RETENCIONES DEL TRABAJADOR</strong></h5>
                    <input id="IdPersona2" name="Idpersona" hidden type="text" value="txtIdPersona" />
                    <div class="form-group">
                        <div class="col-md-3">
                            Asignación Familiar
                            <select id="AsigFamiliar" name="AsigFamiliar" class="form-control AsigFamiliar" onchange="AsignacionFam(); Retenciones(); SueldoNeto(); SeguroSalud()">
                                <option selected disabled="disabled">Seleccione</option>
                                <option value="930">Si</option>
                                <option value="0">No</option>
                            </select>
                        </div>
                        <div class="col-md-3">
                            Asignación Familiar S/.
                            <input id="AsigFam" name="txtAsigFam" class="form-control" placeholder="S/." disabled type="text" onkeyup="AsignacionFam()">
                        </div>
                        <div class="col-md-3">
                            Otros S/.
                            <div class="input-group">
                                <input type="text" id="Otros" name="txtOtros" placeholder="S/." disabled class="form-control" onkeyup="IngresoBruto(); SueldoNeto()">
                                <span class="input-group-addon">
                                    <input type="checkbox" onclick="InhabilitaOtros(this); IngresoBruto(); SueldoNeto()">
                                </span>
                            </div>
                        </div>
                        <div class="col-md-3">
                            Ingreso Bruto S/.
                            <input id="IngresoB" name="txtRB" readonly class="form-control" type="text" placeholder="S/." onkeyup="Retenciones()">
                        </div>
                        <div class="col-md-3">
                            Retención Obligatoria S/.
                            <input id="RetencionXAporte" name="txtAporteOblig" class="form-control" type="text" placeholder="S/." readonly>
                        </div>
                        <div class="col-md-3">
                            Ingreso Neto S/.
                            <input id="IngresoN" name="txtRN" class="form-control" type="text" placeholder="S/." readonly>
                        </div>
                    </div><hr />
                    @*APORTACIONES DEL EMPLEADOR*@
                    <h5><strong>APORTACIONES DEL EMPLEADOR</strong></h5>
                    <div class="form-group">
                        <div class="col-md-3">
                            ESSalud S/.
                            <input id="ESSalud" name="txtEssalud" class="form-control" type="text" readonly placeholder="S/.">
                        </div>
                        <div class="col-md-3">
                            SCTR
                            <select id="SeguroAdic" name="cboSCTR" class="form-control" onchange="SeguroSCTR(); AporteTotal()">
                                <option selected disabled="disabled">Seleccione</option>
                                <option value="1.25">Si</option>
                                <option value="0">No</option>
                            </select>
                        </div>
                        <div class="col-md-3">
                            SCTR S/.
                            <input type="text" id="SCTR" name="txtSCTR" readonly placeholder="S/." class="form-control" onkeyup="SeguroSCTR()">
                        </div>
                        <div class="col-md-3">
                            Aporte Total S/.
                            <input id="AporteEmpleador" name="txtAporteTotal" class="form-control" type="text" readonly placeholder="S/.">
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-md-3">
                            <button type="button" class="btn btn-primary">Guardar</button>
                        </div>
                    </div>
                }
            </fieldset>
        </form>
    </div>
</div>

@section scripts {

    <script type="text/javascript">
        function AsignacionFam() {
            caja = document.forms["sumar"].elements;
            var Asignacion = Number(caja["AsigFamiliar"].value);
            var PorcentajeAF = 0.10;
            var SueldoB = Number(caja["Sueldo"].value);

            Resultado = (Asignacion * PorcentajeAF);
            caja["AsigFam"].value = (Resultado);

            if (!isNaN(Resultado)) {
                var MontoTotal = Resultado + SueldoB;
                caja["IngresoB"].value = (MontoTotal);
            }
        }
    </script>

    <script type="text/javascript">
        function InhabilitaOtros(chk) {

            obj = chk.form;
            if (chk.checked) {
                obj.Otros.disabled = false;
                obj.Otros.value = "";
                document.getElementById("Otros").focus();
            } else {
                obj.Otros.value = 0;
                obj.Otros.disabled = true;
            }
        }

        function IngresoBruto() {
            caja = document.forms["sumar"].elements;
            var Sueldo = Number(caja["Sueldo"].value);
            var Asignacion = Number(caja["AsigFam"].value);
            var Otros = Number(caja["Otros"].value);

            Resultado = (Sueldo + Asignacion + Otros);
            caja["IngresoB"].value = (Resultado);

            if (!isNaN(Resultado)) {
                var MontoTotal = Sueldo + Asignacion + Otros;
                caja["IngresoB"].value = (MontoTotal);
            }
        }

        $(document).ready(function () {
            $("#Sueldo").append(function () {
                var value = $(this).val();
                $("#IngresoB").val(value);
            });
        });

        function Retenciones() {
            caja = document.forms["sumar"].elements;
            var Sueldo = Number(caja["Sueldo"].value);
            var Asignacion = Number(caja["AsigFam"].value);
            var AporteOb = 0.14;

            Resultado = (Sueldo + Asignacion) * AporteOb;
            caja["RetencionXAporte"].value = Math.round(Resultado);
        }

        function SueldoNeto() {
            caja = document.forms["sumar"].elements;
            var Sueldo = Number(caja["IngresoB"].value);
            var RetencionXAporte = Number(caja["RetencionXAporte"].value);

            Resultado = Sueldo - RetencionXAporte;
            caja["IngresoN"].value = Resultado;

            if (!isNaN(Resultado)) {
                var SueldoN = Sueldo - RetencionXAporte;;
                caja["IngresoN"].value = (SueldoN);
            }
        }
    </script>

    <script type="text/javascript">
        function SeguroSalud() {
            caja = document.forms["sumar"].elements;

            var Sueldo = Number(caja["Sueldo"].value);
            var Asignacion = Number(caja["AsigFam"].value);
            var PorcentajeAF = 0.09;

            Resultado = (Sueldo + Asignacion) * PorcentajeAF;
            caja["ESSalud"].value = (Resultado);
        }
    </script>

    <script type="text/javascript">
        function SeguroSCTR() {
            caja = document.forms["sumar"].elements;

            var Sueldo = Number(caja["Sueldo"].value);
            var Asignacion = Number(caja["AsigFam"].value);
            var Porcentaje = Number(caja["SeguroAdic"].value);
            var PorcentajeSCTR = Porcentaje / 100;

            Resultado = (Sueldo + Asignacion) * PorcentajeSCTR;
            caja["SCTR"].value = Math.round(Resultado);

            if (!isNaN(Resultado)) {
                var MontoTotal = (Resultado);
                caja["SCTR"].value = Math.round(MontoTotal);
            }
        }
    </script>
    <script type="text/javascript">
        function AporteTotal() {
            caja = document.forms["sumar"].elements;

            var ESSalud = Number(caja["ESSalud"].value);
            var SCTR = Number(caja["SCTR"].value);

            Resultado = ESSalud + SCTR;
            caja["AporteEmpleador"].value = (Resultado);
        }
    </script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#IdPersona1").append(function () {
                var value = $(this).val();
                $("#IdPersona2").val(value);
            });
        });
    </script>
}
    
asked by Juan Fernando Dj Jf 29.03.2018 в 09:35
source

1 answer

0

is that your form is not called "add". If you want to give an id you have to use the overload that allows you to add HTML attributes

Html.BeginForm("InsertarRemuneracion", "Remuneracion", FormMethod.Post, new {id="sumar", name="sumar"})
    
answered by 29.03.2018 / 10:50
source