treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Dynamic Order Form [PLUS]

  • Hi!, thanks for everything and all your work. ( great work )
    I write from Limache, Chile. (Language Spanish, so my English is not excellent)
    I like very much, the Dynamic Order Form, I already see the video #50 where you explain what it does.

    But now I have a project where I need multiply 2 fields, then the result multiply itself whit another field.
    all this field are INPUT type..
    so, In your example you have an INPUT and multiply whit a SPAN text

    I want to Multiple like this
    INPUT.n1 * INPUT.n2 = Subtotal.t1 * INPUT.n3 = Subtotal.t2
    INPUT.n1 * INPUT.n2 = Subtotal.t1 * INPUT.n3 = Subtotal.t2
    total.total

    I have this:
    HTML
    <tr class=\"odd\">
    <td class=\"product-title\"><em>UNO</em></td>
    <td class=\"product-title\"><select name=\"cobertura\" style=\"width:150px\">
    <!-- select code --> </select> </td>

    <td class=\"num-pallets\"><input type=\"text\" class=\"num-pallets-input\" id=\"sparkle-num-pallets_1\" name=\"monto\" size=\"10\"></input></td>
    <td class=\"num-pallets2\"><input type=\"text\" class=\"num-pallets-input2\" id=\"sparkle-num-pallets2_1\" name=\"tasa\" size=\"3\"></input></td>
    <td class=\"equals\">=</td>
    <td class=\"row-total\"><input type=\"text\" class=\"row-total-input\" id=\"sparkle-row-total_1\" name=\"prima\" size=\"10\" disabled=\"disabled\"></input></td>
    <td class=\"equals\">|</td>
    <td class=\"num-pallets3\"><input type=\"text\" class=\"num-pallets-input3\" id=\"sparkle-num-pallets3_1\" name=\"tax\" size=\"3\" value=\"2\"></input></td>
    <td class=\"equals\">=</td>
    <td class=\"row-total2\"><input type=\"text\" class=\"row-total-input2\" id=\"sparkle-row-total2\" name=\"montotax\" size=\"10\" disabled=\"disabled\"></input></td>
    </tr>




    --- I realize that the ID must be different ... in the different tr ... or not??
    <td class="num-pallets"><input type="text" class="num-pallets-input" id="sparkle-num-pallets_1" name="monto" size="10"></input></td>

    .JS


    $(function(){

    $('.num-pallets-input2').blur(function(){

    var $uno = $('.num-pallets-input');//****
    var $unoval = $uno.val();//****

    var $this = $(this);
    var numPallets = $this.val();

    if ( (IsNumeric(numPallets)) && (numPallets != '') {

    var rowTotal = numPallets * $unoval;

    $this
    .css(\"background-color\", \"white\")
    .parent().parent()
    .find(\"td.row-total input\")
    .val(rowTotal);

    } else {

    $this.css(\"background-color\", \"#ffdcdc\");

    };


    });

    });


    ///7 NUEVA FUNCION PARA SACAR EL MONTO TAX
    $(function(){

    $('.num-pallets-input3').blur(function(){

    var $uno = $('.row-total-input');//****
    var $unoval = $uno.val();//****

    var $this = $(this);
    var numPallets = $this.val();

    if ( (IsNumeric(numPallets)) && (numPallets != '') ) {

    var rowTotal = numPallets * $unoval;

    $this
    .css(\"background-color\", \"white\")
    .parent().parent()
    .find(\"td.row-total2 input\")
    .val(rowTotal);

    } else {

    $this.css(\"background-color\", \"#ffdcdc\");

    };

    calcProdSubTotal();
    calcTotalPallets();
    calcShippingTotal();
    calcOrderTotal();

    });

    });


    Yes, I suck in .js, I took the example .js and I copy/paste, take some variable... like this:

    var $uno = $('.row-total-input');//**** take the .row-total-input from the form which I calculated whit the first function
    var $unoval = $uno.val();//**** take the val of the .row-total-input ...

    but and dont know much of .js
    :(

    but it work, ah...
    but don't work well ..
    calculate all the values for the first value .. mmmmmmmm. like this

    100 * 2 = 200 *10 = 2000
    324 * 3 = 300 * 20 = 4000

    or
    A * B = (A*B) * D = (A*B*D)
    A1 * B1 = (A*B1) * D1 = (A*B1*D1)
    you see...

    well... please if you can give and eyes or 2,, and post the thinking ... THANKS

  • $(function(){

    $('.num-pallets-input').blur(function(){

    var $this = $(this);

    var numPallets = $this.val();
    var multiplier = $this
    .parent().parent()
    .find(\"td.num-pallets2 input\")
    .val();

    if ( (IsNumeric(numPallets)) && (numPallets != '') ) {

    var rowTotal = numPallets * multiplier;

    $this
    .css(\"background-color\", \"white\")
    .parent().parent()
    .find(\"td.row-total input\")
    .val(rowTotal);

    //rowTotal <- esto e muestra en row-total input

    $('.num-pallets-input3').blur(function(){

    var $this = $(this);

    var tax = $this.val();

    if ( (IsNumeric(numPallets)) && (numPallets != '') ) {

    var rowTotal2 = tax * rowTotal;

    $this
    .css(\"background-color\", \"white\")
    .parent().parent()
    .find(\"td.row-total2 input\")
    .val(rowTotal2);

    };
    });


    } else {

    $this.css(\"background-color\", \"#ffdcdc\");

    };

    calcProdSubTotal();
    calcTotalPallets();
    calcShippingTotal();
    calcOrderTotal();

    });

    });


    por si alguien lo quiere....

    maybe someone else need this....
    thank For The INSPIRATION ...