Note that there are some explanatory texts on larger screens.

plurals
  1. POStuck on how to add a "select all" function with discount
    primarykey
    data
    text
    <p>I basically have a form that calculates totals in a list by selecting check boxes. However, I'd like to modify it so that people can select "check all" so it selects all the check boxes, and makes the total $999 rather than what it would be if they just added all the items one by one. So it's basically a discount if they select all of the check boxes. Has anyone done something like this before? Any help would be greatly appreciated.</p> <p>Here is the code I have right now, and I'm just stuck on this...</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;link rel="shortcut icon" type="image/x-icon" href="../favicon.ico" /&gt; &lt;link rel="icon" type="image/x-con" href="../favicon.ico" /&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt; &lt;!-- Begin JavaScript --&gt; &lt;!--- ADDING THE CHECK BOXES ---&gt; &lt;script language="javascript" type="text/javascript"&gt; //Define global form total: var form_amount=0; //Define function to manipulate the form total per item selected/deselected: function CheckChoice(whichbox) { //If box was checked, accumulate the checkbox value as the form total, //Otherwise, reduce the form total by the checkbox value: if (whichbox.checked == false) { form_amount -= eval(whichbox.value); } else { form_amount += eval(whichbox.value); } //Re-set displayed total on form: document.MyAddingForm.amount.value = eval(form_amount); } //Define function to init the form on reload: function InitForm() { //Reset the displayed total on form: document.MyAddingForm.amount.value='0'; //Set all checkboxes on form to unchecked: for (xx=0; xx &lt; document.MyAddingForm.elements.length; xx++) { if (document.MyAddingForm.elements[xx].type == 'checkbox') { document.MyAddingForm.elements[xx].checked = false; } } } &lt;/script&gt; &lt;title&gt;Add Boxes&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;form action="BLANKPAGE_TEST_2.cfm" method="post" id="addCommentForm" name="MyAddingForm" onsubmit="return submit_form()"&gt; &lt;table id="commentTable"&gt; &lt;tr&gt; &lt;th&gt;&lt;label&gt;Item One&lt;/label&gt;&lt;/th&gt; &lt;td&gt; &lt;label&gt;&lt;input type="checkbox" name="ItemOne" value="119.00" onclick="CheckChoice(this);" onfocus="startCalc();" onblur="stopCalc();" class="checkbox" /&gt; $119&lt;/label&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;th&gt;&lt;label&gt;Item Two&lt;/label&gt;&lt;/th&gt; &lt;td&gt; &lt;label&gt;&lt;input type="checkbox" name="ItemTwo" value="119.00" onclick="CheckChoice(this);" onfocus="startCalc();" onblur="stopCalc();" class="checkbox" /&gt; $119&lt;/label&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;th&gt;&lt;label&gt;Item Three&lt;/label&gt;&lt;/th&gt; &lt;td&gt; &lt;label&gt;&lt;input type="checkbox" name="ItemThree" value="119.00" onclick="CheckChoice(this);" onfocus="startCalc();" onblur="stopCalc();" class="checkbox" /&gt; $119&lt;/label&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;th&gt;&lt;label&gt;Item Four&lt;/label&gt;&lt;/th&gt; &lt;td&gt; &lt;label&gt;&lt;input type="checkbox" name="ItemFour" value="119.00" onclick="CheckChoice(this);" onfocus="startCalc();" onblur="stopCalc();" class="checkbox" /&gt; $119&lt;/label&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;th&gt;&lt;label&gt;Item Five&lt;/label&gt;&lt;/th&gt; &lt;td&gt; &lt;label&gt;&lt;input type="checkbox" name="ItemFive" value="119.00" onclick="CheckChoice(this);" onfocus="startCalc();" onblur="stopCalc();" class="checkbox" /&gt; $119&lt;/label&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;th class="altTH"&gt;&lt;label&gt;Total $:&lt;/label&gt;&lt;/th&gt; &lt;td class="altTD"&gt;&lt;input type="text" name="amount" readonly="readonly" class="inputSmall" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    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