Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting a Total
    primarykey
    data
    text
    <p>Okay, The challenge is relatively small but it's a fly buzzing around my head. Take a look in jQuery at $("#list_total"+table_number).text("$"+grand_total[table_number].toFixed(2));</p> <p>What I've tried to do is grand_total[table_number] += sub_total; but I keep getting NaN.</p> <p><strong>CSS</strong></p> <pre><code> .guest_table { float:left; position: relative; margin-left: 30px; width: 280px; } h1 { text-align: center; } table { margin-left: auto; margin-right: auto; width: 425px; } table, tr { border: 5px solid black; -moz-border-radius: 10px; -webkit-border-radius: 10px; border-radius: 10px; /* future proofing */ -khtml-border-radius: 10px; /* for old Konqueror browsers */ } tr { height: 65px; } .submit { text-align: center; } .input { border: none; background: #fff url(../images/rounded-corner.png) no-repeat left top; background-size:185px 37px; width: 160px; padding: 10px; } .input:focus { background-color: #ffff33 ; } #submit_form { border: 50px; padding: 10px; margin-left: auto; margin-right: auto; } .error { text-align: center; color: red; font-size: 20px; margin-bottom: 20px; background-color: yellow; width: 25%; margin-left: auto; margin-right: auto; } .list_total { display: inline-block; padding-left: 5px; } #option_list { width: 25%; } #already_paid { text-align: center; } input[type=submit]:hover,input[type=reset]:hover { background-color: #8F5B00; color: white; } button, input[type=submit] { margin-left: 10px; } button:hover { background-color: #8F5B00; color: white; } </code></pre> <p><strong>Codeigniter View</strong></p> <pre><code>&lt;?php echo validation_errors(); ?&gt; &lt;?php $total_guests = count($results); $attributes = array( 'id' =&gt; 'submit_form' ); echo form_open('main/form_validation/options'); ?&gt; &lt;div id="center"&gt; &lt;?php foreach ($results as $result) { ?&gt; &lt;table class="guest_table" id="guest_&lt;?php echo $result-&gt;id; ?&gt;"&gt; &lt;th&gt; &lt;?php echo $result-&gt;full_name; ?&gt; &lt;/th&gt; &lt;tr id="option_list"&gt; &lt;td&gt; &lt;?php $b = $price2 &gt; 0 ? " $" . $price2 : "N/A"; $day = array( array( 'name' =&gt; 'friday_performance_' . $result-&gt;id, 'id' =&gt; 'friday_performance' . $result-&gt;id, 'value' =&gt; 'friday_performance' ), array( 'name' =&gt; 'friday_banquet_' . $result-&gt;id, 'id' =&gt; 'friday_banquet' . $result-&gt;id, 'value' =&gt; 'friday_banquet' ), array( 'name' =&gt; 'saturday_' . $result-&gt;id, 'id' =&gt; 'saturday' . $result-&gt;id, 'value' =&gt; 'saturday' ), ); $meal_pref = array( array( 'name' =&gt; 'meal_' . $result-&gt;id, 'id' =&gt; 'chicken', 'value' =&gt; 'chicken' ), array( 'name' =&gt; 'meal_' . $result-&gt;id, 'id' =&gt; 'fish', 'value' =&gt; 'fish' ), array( 'name' =&gt; 'meal_' . $result-&gt;id, 'id' =&gt; 'vegetarian', 'value' =&gt; 'vegetarian' ), ); echo form_checkbox($day[0]); ?&gt;&amp;nbsp;&amp;nbsp; Friday Performance &lt;?php echo " $" . $price1; ?&gt;&lt;br&gt; &lt;?php echo form_checkbox($day[1]); ?&gt;&amp;nbsp;&amp;nbsp;Friday Banquet &lt;?php echo $b; ?&gt;&lt;br&gt; &lt;div class="meal_choice" id='meal_choice&lt;?php echo $result-&gt;id; ? &gt;'&gt; &lt;?php echo form_radio($meal_pref[0]); ?&gt;&amp;nbsp;&amp;nbsp;Chicken &lt;br&gt; &lt;?php echo form_radio($meal_pref[1]); ?&gt;&amp;nbsp;&amp;nbsp;Fish &lt;br&gt; &lt;?php echo form_radio($meal_pref[2]); ?&gt;&amp;nbsp;&amp;nbsp;Vegetarian&lt;br&gt; &lt;/div&gt; &lt;?php echo form_checkbox($day[2]); ?&gt;&amp;nbsp;&amp;nbsp;Saturday Workshop w/lunch &lt;?php echo " $" . $price3; ?&gt;&lt;br&gt; &lt;br&gt;&lt;br&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; Total:&lt;div class="list_total" id="list_total&lt;?php echo $result-&gt;id; ?&gt;"&gt;&lt;/div&gt; &lt;/td&gt; &lt;/table&gt; &lt;?php } ?&gt; &lt;/div&gt; &lt;div class="submit"&gt; &lt;?php echo ("&lt;input type='hidden' name='email' value=" . $this-&gt;session-&gt;userdata('email') . "&gt;"); $data = array( 'name' =&gt; 'submit', 'id' =&gt; 'submit', 'value' =&gt; 'Complete Form', 'type' =&gt; 'submit' ); echo form_submit($data); echo form_button('exit', 'Exit'); ?&gt; &lt;/div&gt; &lt;?php echo form_close(); ?&gt; </code></pre> <p><strong>jQuery</strong></p> <pre><code>&lt;script&gt; $(document).ready(function(){ $(".list_total").text("$0.00"); $(".meal_choice").hide(); var total_attending = (&lt;?php echo $total_guests; ?&gt; + 1); $("[name='exit']").click(function(){ window.location.href='&lt;?php echo base_url(); ?&gt;/main/logout'; }); var table_number = 0; $('.guest_table').click(function(){ var table_id = $(this).attr('id'); table_number = parseInt(table_id.charAt(table_id.length-1)); }); var grand_total=[]; grand_total[table_number]=0.00; $(':checkbox').change(function(){ switch($(this).attr('id')) { case 'friday_performance' + table_number: var sub_total= 0.00; sub_total = parseInt(friday_performance()); grand_total[table_number] += sub_total; $("#list_total"+table_number).text("$"+ grand_total[table_number].toFixed(2)); break; case 'friday_banquet' + table_number: var sub_total= 0.00; sub_total = parseInt(friday_banquet()); grand_total[table_number] += sub_total; $("#list_total"+table_number).text("$"+ grand_total[table_number].toFixed(2)); break; case 'saturday' + table_number: var sub_total= 0.00; sub_total += parseInt(saturday()); grand_total[table_number] = sub_total; $("#list_total"+table_number).text("$"+ grand_total[table_number].toFixed(2)); break; } }); function friday_performance () { if ( $("#friday_performance"+table_number).is(":checked")) { var price1 = &lt;?php echo $price1; ?&gt;; return price1; }else if ( $("#friday_performance"+table_number).not(":checked")) { var price1 = 0; return price1; } } function friday_banquet () { if ($("#friday_banquet"+table_number).is(":checked")) { $("#meal_choice"+table_number).show("slow"); var price2 = &lt;?php echo $price2; ?&gt;; return price2; }else if ($("#friday_banquet"+table_number).not(":checked")) { $("#meal_choice"+table_number).hide("slow"); $('input:radio').prop("checked",false); var price2 = 0; return price2; } } function saturday() { if ( $("#saturday"+table_number).is(":checked")) { var price3 = &lt;?php echo $price3; ?&gt;; return price3; }else if ( $("#saturday"+table_number).not(":checked")) { var price3 = 0; return price3; } } $("#submit").click(function(){ alert("Got it!"); }); }); &lt;/script&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload