JSFiddle - React, Tailwind, and code Playground

by Chandu

HTML

<script src="http://thetimbanks.com/demos/js/jquery.datalink.js"></script>
<table cellspacing="0">
        <caption id="title4">
            Sprinkles (5 - 6 oz.)
                    </caption>
        <thead>
            <tr>
                <th>&nbsp;</th>
                                    <td >Price</td>
                                    <td >Quantity</td>
                            </tr>
        </thead>
        <tbody>
                        <tr class="statement4">
                <th><label>Lemon</label></th>
                                <td title="Yes" >
                    <label>$6.50</label>
                </td>
                                <td title="No" >
                    <input id="s1" name="s1" class="field text small" type="text" value="0"/>
                </td>
                            <tr class="statement4">
                <th><label>Sweet Apple</label></th>
                                <td title="Yes" >
                    <label>$6.50</label>
                </td>
                                <td title="No" >
                    <input id="s2" name="s2" class="field text small" type="text" value="0"/>
                </td>

                <tr class="statement4">
                <th><label>Sweet Caramel</label></th>
                                <td title="Yes" >
                    <label>$6.50</label>
                </td>
                                <td title="No" >
                    <input id="s3" name="s3" class="field text small" type="text" value="0"/>
                </td>

                <tr class="statement4">
                <th><label>Sweet Cinnamon</label></th>
                                <td title="Yes" >
                    <label>$6.50</label>
                </td>
                                <td title="No" >
                    <input id="s4" name="s4" class="field text small" type="text" value="0"/>
                </td>

                <tr class="statement4">
               ...

JavaScript

var total = 0.0;
var all=new Array();
for(var i = 0; i < 49; i++)
    all[i] = 0;

//....I OMMITTED CODE HERE FOR THE REST OF THE onkeyup FUNCTIONS
document.getElementById("s1").onkeyup = function() {
    if(this.value != "") {
        all[44] = (parseInt(this.value,10) * 6.50);
    }
    else {
        all[44] = 0;
    }
    updateIt();
};

document.getElementById("s2").onkeyup = function() {
    if(this.value != "") {
        all[45] = (parseInt(this.value,10) * 6.50);
    }
    else {
        all[45] = 0;
    }
    updateIt();
};

document.getElementById("s3").onkeyup = function() {
    if(this.value != "") {
        all[46] = (parseInt(this.value,10) * 6.50);
    }
    else {
        all[46] = 0;
    }
    updateIt();
};
document.getElementById("s4").onkeyup = function() {
    if(this.value != "") {
        all[47] = (parseInt(this.value,10) * 6.50);
    }
    else {
        all[47] = 0;
    }
    updateIt();
};

document.getElementById("s5").onkeyup = function() {
    document.getElementById("mySpan").innerHTML = "WOAH";

    if(this.value != "") {
        all[48] = (parseInt(this.value,10) * 6.50);
    }
    else {
        all[48] = 0;
    }
    updateIt();
};

function updateIt() {
    var theTotal = 0;
    for(var j = 0; j < 49; j++)
        theTotal += all[j];

    theTotal = all[48];
    document.getElementById("mySpan").innerHTML = "$" + theTotal.toFixed(2);
}