Ask a Question related to Macromedia ColdFusion, Design and Development.
-
alpenman #1
Summarize values when checkbox is checked
Hello all,
The output of some query shows for example 10 records with invoice prices.
Before each record is an unchecked checkbox. What I like to do is to check some
checkboxes to control the total price of the checked invoices. How can I manage
that?
Greetings,
Rudy
alpenman Guest
-
Get Checkbox "Checked" value on form submit
How do I get whether a checkbox is ticked in a form on a form's submission (true or false)? How do I use the Request object in ASP? -
DataGrid with CheckBox - How to read checked rows
I have added a checkbox to a dataset that I bind to a datagrid: DataColumn colBoolean = new DataColumn ("chkBox"); colBoolean.DataType =... -
Saving checkbox states (checked or unchecked)?
Hello. I'm creating a basic form with checkboxes for "yes/no". Is there a way for the state of the checkboxes to be saved by the user (using regular... -
Find what checkbox is checked in javascript
I have to sets of checkboxes. The second is to delete the row. So when I click that checkbox I want to add it to an array. I also need to take it... -
Capturing checked event for Template based checkbox.
Getting to grips with the datagrid better than I thought, however I've hit another problem which hopefully someone will be able to help (again.) ... -
MikerRoo #2
Re: Summarize values when checkbox is checked
What do you mean "control the total price of the checked invoices"?
Do you want to display the sum of the checked invoices? Javascript can
easily do that.
Or is it something else?
Regards,
-- MikeR
MikerRoo Guest
-
alpenman #3
Re: Summarize values when checkbox is checked
Hello Mike,
Yes... I want to display the sum of the checked invoices...
Greetings,
Rudy
alpenman Guest
-
Neculai Macarie #4
Re: Summarize values when checkbox is checked
> Hello Mike,
Make those checkboxes submit the form to the server and calculate the sum on>
> Yes... I want to display the sum of the checked invoices...
the server.
<input type="checkbox" name="product_id#id#" onclick="this.form.submit();">
--
<mack />
Neculai Macarie Guest
-
MikerRoo #5
Re: Summarize values when checkbox is checked
Ok, the attached code shows you one way to do it -- without having to talk to
the server at all.
Just be sure to validate and recalculate, on the server, when the user finally
submits the form. This guards against acts of browsers, hackers, and nature.
Regards,
-- MikeR
<style type="text/css">
#ItemTotalDisplay /*--- Double pound signs needed for CF. Use single
pound otherwise. ---*/
{
background-color: #CCFFCC;
border: 1px solid black;
padding: 6px;
font-size: larger;
}
</style>
<form name="frmListItems">
<p id="ItemTotalDisplay">
<!--- This next span will be overwritten by javascript. --->
Total: $<span id="domItemSumDisplay"> 0 </span>
</p>
<label for="CB_1">
<input name="cbItemList" type="checkbox" id="CB_1" value="10.99"
onclick="cjsSumChkBoxPrices ('frmListItems', 'cbItemList',
'domItemSumDisplay');">
Item 1 for $10.99
</label>
<label for="CB_2">
<input name="cbItemList" type="checkbox" id="CB_2" value="3.02"
onclick="cjsSumChkBoxPrices ('frmListItems', 'cbItemList',
'domItemSumDisplay');">
Item 2 for $3.02
</label>
</form>
<script type="text/javascript">
function cjsSumChkBoxPrices (sFormName, sCB_GrpName, sOutputElementID)
{
var zCB_Array = eval ("document.forms." + sFormName + "." +
sCB_GrpName);
var fSum = 0;
var zCntDisplay = document.getElementById (sOutputElementID);
var iNumCBoxes = zCB_Array.length;
for (iCBIdx=0; iCBIdx < iNumCBoxes; iCBIdx++)
{
if (zCB_Array[iCBIdx].checked)
{
fSum += (zCB_Array[iCBIdx].value - 0); //-- minus zero
forces number convert.
}
}
//--- Write the sum to the display span. ---
zCntDisplay.innerHTML = fSum;
}
</script>
MikerRoo Guest
-
alpenman #6
Re: Summarize values when checkbox is checked
Hello Mike,
I have implemented your code in the page and it works fine for me! I have an
extra checkbox for each record because the value in the original checkbox is
the ID of the record and not the invoice value (the money).
Thanks in advance,
greetings Rudy
alpenman Guest
-
MikerRoo #7
Re: Summarize values when checkbox is checked
Thanks for the feedback.
But, having two checkboxes may be annoying to your users.
Post another question if you want help with that. (One solution would be for
your code to write a javascript lookup table that cjsSumChkBoxPrices() would
then use to translate DB ID to price.)
Regards,
-- MikeR
MikerRoo Guest



Reply With Quote

