Help with an Ajax Calculator!

Discussion in 'JavaScript' started by AZMac, May 9, 2008.

  1. #1
    Hi! I´m a newbie spanish programmer and i trying to do an calculator banner in javascript with ajax.. but i can´t do it works..

    Well, the objective is make an aplication banner is like this : http://www.fundaciontripartita.es/publico/FormularioCalculoCredito2007.aspx

    but the calculator must be show a varying in the label, without push the button "calcular" .. This is the code:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">

    <html>

    <head>
    <title>
    Calculadora Ajax
    </title>



    <script src="jquery-1.2.3.min.js" type="text/javascript"> </script>
    <script type="text/javascript">

    function validar(formu)
    {
    numemp = parseInt(formu.numeroEmpleados.value, 10); //convierte en valores enteros los datos del formulario (base 10)
    tc1 = parseInt(formu.TC1.value, 10);
    cf = parseInt(formu.CF.value, 10);

    if ( isNaN(numemp) && isNaN(tc1) ) { //valida que sean numeros
    alert("Debe cumplimentar los dos campos con valores numericos.");
    return false;

    }
    if ( numemp < 0 || tc1 < 0 ) { //valida que sean positivos
    alert("Los valores numericos introducidos deben ser positivos.");
    return false;
    //ok, envio formulario
    }


    if (numemp >= 6 && numemp <=9 )
    { cf = tc1 * 0.007;
    alert("Credito formativo = " + cf);
    return true;
    }
    if (numemp > 10 && numemp < 49 )
    { cf = tc1 * 0.007 * 0.075;
    alert("Credito formativo = " + cf);
    return true;
    }
    if (numemp > 50 && numemp < 249 )
    { cf = tc1 * 0.007 * 0.060;
    alert("Credito formativo = " + cf);
    return true;
    }
    if (numemp > 250 )
    { cf = tc1 * 0.007 * 0.050;
    alert("Credito formativo = " + cf);
    return true;
    }
    }

    </script>

    </head>

    <body>


    <form name="miFormu" onSubmit="return validar(this);">

    <p>

    <input name="numeroEmpleados" type="text" size="10"> Numero empleados<br>
    <input name="TC1" type="text" size="10"> TC1<br>
    <input type="submit" name="miSubmit" value="Consultar">

    </p>

    </form>





    </body>


    </html>

    I think the function code is right but im not sure..whats wrong? perhaps the html code?.. i need your help urgently!!

    Thanks!
     
    AZMac, May 9, 2008 IP