Finding End Result With Checkboxes / Radio Buttons In One Calculation

Feb 27, 2009

Having trouble calculating the final cost of choices made by a user. I have 4 radio buttons and 2 checkboxes. The first three radio buttons are, all intensive purposes, chocolates with the last radio button stating that the user doesn't want any of the chocolates. The two checkboxes are a milkshake and candyfloss respectively. The user may only choose one of the three chocolates and optionally the milkshake, candyfloss or both.

What I have so far is as follows:
Javascript code
function calc(sec,val,item)
{
if(!item) {
var item = null;
}
switch(sec)
{

case 1:
Some code for a different function.
break

case 2:
cValue = parseInt(document.getElementById("purchaseTotal").value);
if(item.checked){
document.getElementById("purchaseTotal").value = cValue+val;
}else{
document.getElementById("purchaseTotal").value = cValue-val;
} break;
} }
html
<td>Chocolate 1: ZAR 5.00</td>
<td><input name="chocolate" type="radio" id="chocolate" value="" onClick="calc(2,5.00, this);">
</td>
<td> </td>
</tr>
<tr>
<td>Chocolate 2: ZAR 5.00</td>
<td><input name="chocolate" type="radio" id="chocolate" value="" onClick="calc(2,5.00, this);">
</td>
<td> </td>
</tr>
<tr>
<td>Chocolate 3: ZAR 1 200.00</td>
<td><input name="chocolate" type="radio" id="chocolate" value="" onClick="calc(2,5.00, this);">
</td>
<td> </td>
</tr>
<tr>
<td>I do not wish to buy a chocolate.</td>
<td><input name="chocolate" type="radio" id="chocolate" value="" onClick="calc(2,0, this);">
</td>
<td> </td>
</tr>
<tr>
<td>Milkshake: ZAR 13.00</td>
<td><input type="checkbox" name="milkshake" id="milkshake" value="" onClick="calc(2,13.00, this);"></td>
<td> </td>
</tr>
<tr>
<td>Candyfloss: ZAR 8.00</td>
<td><input type="checkbox" name="candyfloss" id="candyfloss" value="" onClick="calc(2,8.00, this);"></td>
<td> </td>
</tr>
<tr>
<td colspan="3" align="right" valign="top">Total ZAR <input name="purchaseTotal" type="text" id="purchaseTotal" value="0"></td>

What happens at the moment is that clicking on one radio button doesn't subtract the amount from the previous selected radio button and clicking on the same radio button just keeps adding its value to the total. I'd like it to do the opposite and not add to the total if clicked repeatedly and if another radio button is selected the amount of the previous radio button must be deducted from the total.

View 1 Replies


ADVERTISEMENT

JQuery :: Auto-Calculation Based On Radio Buttons

Apr 12, 2011

I am stuck on the last part of this jQuery auto-calculation script that I am working on. I want to automatically re-calculate the subtotal values based on a "radio button click". The calculation will automatically add a 10% discount when the radio button "special_(n)" "yes" value gets clicked, but revert back to normal price when the "no" value gets clicked.

View the script in action here: [url] (tip): enter a value into the 'qty' field, and the totals will auto calculate.

HTML:

View 1 Replies View Related

Checking Used Radio Buttons And Checkboxes?

Jul 20, 2005

It is for checking out used radiobuttons or checkboxes.
<script
<!--
function pruefen(){return true}
-->
</script>
<script language="JAvaScript1.1"><!--
function pruefen(f){
[URL] .....

View 4 Replies View Related

Show/Hide Checkboxes With Radio Buttons?

Feb 10, 2011

I'd like to ask a user to choose from one of two radio buttons. The first radio button will show three checkboxes. The second radio button does nothing.How do I do this?

View 9 Replies View Related

Option Calculator Form With Radio Buttons And Checkboxes

Aug 23, 2010

I am trying to make an option calculator for my site. The user will click on various radio buttons and checkboxes, before pressing the calculate button. The button will then add up all the values to show the overall figure. The code shown below is what I have so far.

Code:
function calcMe(){
for (var i=0; i < document.form.radio.length; i++){
if (document.form.radio[i].checked){
var rad_val = document.form.radio[i].value;
}} if (document.form.radio1.checked) {
document.form.result.value = rad_val;
} if (document.form.radio2.checked) { .....

The first javascript is to show the value of the radio button with the textfield attached - when the user puts a number in the textfield, it will update the value of the radio button. The second javascript is to check the document for the clicked radio buttons and checkboxes. It then adds up all the clicked values to show the answer. The problem that I am having is to put these two javascripts together so as the radio button is updated with the text field value as well as adding up all the clicked values.

View 1 Replies View Related

Alternative To Checkboxes And Radio Buttons - Click On Words ThatHighlight

Mar 25, 2007

I have an application with an input form that sometimes has a hundred or
so check boxes organized into groups of about 10 choices. The boxes are
difficult to check because the target is small and after the user
chooses a dozen or so choices, the result is difficult to see.

I was thinking that an alternative would be to just have the single word
choices highlight after being checked. This would result in bigger
targets, denser forms, and would be easier to see.

Does anyone have any pointers to pages or examples that implement a
similar solution using CSS and Javascript?

View 2 Replies View Related

Using Visible/hidden Radio Buttons - Create Questionnaire Style Series Of Radio Buttons

Jul 13, 2010

I'm trying to create a questionnaire style series of radio buttons which are hidden and then a different set of radio buttons displayed depending on the previous answer. eg

Q1 Is it a man? (if select yes then display)

Q2 Is he called John? (if no then display)

Q3 Is he called Gary? and so on...

I've been testing using the code below but wondered if anyone had any ideas on how this could be done easily?

View 2 Replies View Related

Display The Result Of The Calculation In The Textbox With Id Price?

Sep 19, 2009

This is my very first javascript (I have limited knowledge C++ and php). I am trying to make an instant quote calculator, but having some trouble.I want to display the result of the calculation in the textbox with id price.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>[code]........

View 8 Replies View Related

Pass Database Query Result For Calculation?

Feb 25, 2009

i having problem on passing the database query result to the javascritpt for calculation.i doing a program that need to calculate the total_price for the purchase items. i use getString to get the foodID, f_item and the unit_price from database, then i need to use the unit_price for doing the calculation in javascript. after get the data from database, the unit_price is used to multiple with the qty that user input to calculate the total_price.since there are several row of data get from database, so user need to enter the qty for each item and then press [Calculate_db] button to perform the calculated result. hence, the total_price for each item is calculated and the sum of all the total_price also being calculated and display in the page.now, i having problem on pass the unit_price to the javascript for calculation.

<form name="formCalc2">
<table>
<tr>

[code]....

View 1 Replies View Related

Display A Calculation Result With A Thousands Separator?

May 9, 2011

I'm trying to display a calculation result with a thousands separator (eg $1200 to $1,200).

what javascript code I can use to achieve this?

This is my 'calculate' button....

<a href="#TB_inline?height=360&width=380&inlineId=popup" class="thickbox" onClick="checkValue(); calculateTotal(); true" >
<input type="button" name="Button" value="OK" class="OK" /></a>

[Code].....

View 3 Replies View Related

Get Radio Button Validation For Different Sets Of Radio Buttons That Simply Contains Yes & No Buttons

Nov 28, 2009

I'm trying to get a radio button validation for different sets of radio buttons that simply contains Yes & No buttons.

Here's what I'm trying to do:

Question 1: if Yes, then (Alert 1) if No, then (Alert 2) (if Yes, then Question 2 appears) *Up to here I'm happy- can't figure out the rest*

Question 2: if Yes, then (Alert 1) if No, then (Alert 2) (if Yes, then Question 3 appears)

I need the Alerts to be swapped from this point*

Question 3: if Yes, then (Alert 2) if No, then (Alert 1) (if NO, then Question 4 appears)

Identical for Question 5, and for Last Question 6 Alerts swapped back again.)

Here's the script that I managed to piece together:

View 5 Replies View Related

Calculation Form With Radio Button?

Mar 3, 2009

I try to calculate all the number based on selected radio button and display it in the textfield on the same page can someone can tell me the errors and suggest how to make my calculation is right.

[Code]...

View 9 Replies View Related

JQuery :: Finding ID's And Checked Status Of Checkboxes?

Feb 22, 2010

I have a form which I populated with checkboxes having ID based on the records pulled from a table.

[Code]...

View 1 Replies View Related

Radio Buttons - Get The Image To Display Whenthey Click On The Radio Button

Feb 28, 2010

Im trying to configuere a form that a.a radio buttons that allow the user to choose between quarters, nickels, dimes and pennies and show image when click on my radio button.how to get the image to display whenthey click on the radio button?

View 3 Replies View Related

2 Radio Buttons And Submit - Make Each Radio Button Call A Different Page?

Jul 15, 2011

how I can make each radio button call a different page. For example If i click on radio button 1 and click submit it will take me to [url].... and if I click radio button 2 and click submit .

View 7 Replies View Related

Radio Buttons: Preventing The OnClick Event If The Radio Button Is Already Checked

Mar 23, 2009

I have a set of radio buttons each with an onclick event that has a numeric value. When the button is clicked an input box called "Total" is updated with the new value. The problem I'm having is that if a radio button is checked and one clicks on it again then the onclick event is triggered.

Is there any way to prevent the onclick event from triggering if the radio button is already checked?

View 2 Replies View Related

Jquery :: Radio Buttons And Submit - Selected Radio Button's Value To Be Inserted Into The Href Of The Link??

Jan 20, 2011

I have 3 radio buttons with the same name ("myradio"). The value of each is a different URL (eg. value="http:[url]...)I have a link underneath these (<a href="#">Send</a>). I would like the selected radio button's value to be inserted into the href of the link, and if the user selects a different radio button that this changes.

View 1 Replies View Related

When The User Select One Radio Button The Other Radio Buttons Should Disable?

Oct 21, 2011

I have a form with 4 radio buttons, the scenario is, when a user click on a radio button a hidden content will be displayed and the other three radio buttons will be disabled so that at one time a user can only click and view single radio button and the hidden content.Here is my code to show hide the hidden content but i need when the user select one radio button the other radio buttons should disable.

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />[code]......

View 17 Replies View Related

Add The Two Selected Radio Buttons To Checkbox Buttons?

Apr 11, 2010

what i need to do to add all the radio botton and check box. i already finish the add formula on the checkbox but i do not know how to add the two selected radio buttons to my checkbox buttons.for example:

O selected is 80
O 60
O 60

O selected is 15
O 15
O 25[code].....

View 5 Replies View Related

Radio Buttons To Become Submit Buttons

Jun 17, 2011

I want my radio buttons to become submit buttons as well. So when a user clicks on a radio button it submits the action and refreshes the page accordingly. As of now using only using onclick="this.form.submit()" the page only refreshes with no change. Here is a copy of the entire form. It is a custom shipping options form (I did not create it).

<!-- Custom shipping form -->
<form action="" method="post" name="update_shipping">
<table width="300">
<tr>
<td><label>
<input <?php if (!(strcmp($_SESSION['shippingmethod'],"1"))) {echo "checked="checked"";} ?>
[Code]...

View 9 Replies View Related

Radio Button - Result On Alert ?

Nov 10, 2010

I think this one will appear in our finals but no one seems to help me.. always getting error.. a 3 radio buttons and will appear the result on alert or popup? something like YOU SELECTED: "___"

View 1 Replies View Related

Using Buttons To Check And Uncheck Checkboxes

Dec 8, 2010

I'm trying to write some code that uses buttons to check and uncheck certain checkboxes. I am stumped and all the code I have been finding is using for loops to check or uncheck all the boxes, when I just want to check or uncheck certain ones. Here's an example of the type of function I'm trying to use:
function checkSome (form) {
document.myForm.list.one.checked = true;
document.myForm.list.two.checked = true;
document.myForm.list.three.checked = false;
}
And the button:
<input type="button" value="Option 1" onClick="checkSome(this.form)"/>

View 3 Replies View Related

JQuery :: When Using Radio Buttons $_POST['radio']; Returns "on"?

Jun 3, 2011

I am trying to use the jquery radio buttons and everything looks well until I press the submit button.What is passed on in my POST variable for the radio buttons is the string "on" and not at all the name of the button. All of the buttons just returns "on".[URL]

View 3 Replies View Related

Dynamic Display Of Radio/Checkboxes

Jul 23, 2005

I'm looking to display the value of radio buttons and check boxes on the
page before submission. So far I can do most of it. When "Hat" is checked
there are to be no color options available. Click on shirt or pants, you
have three options, (actually four if you chose "None"). Shirts and pants
can have multiple colors.

OK, here is the issue, if you choose a color then change your mind and then
un-check the box, it doubles up the 'display' on the page ("strCavTop"). I
want it to clear the 'display' ("strCavTop") of that one value if the box is
clicked to un-check it.

Is there another way to display the data other than a form text box, like a
table cell or something similar? I willing to bet there is a more
economical way to do this, so if there is I'm open to any suggestions. Code:

View 3 Replies View Related

JQuery :: Finding Selected Radio Button In Internet Explorer With Function / Onchange - Wrong Value Obtained

Feb 24, 2011

The following code works fine in FF and Chrome for getting a radio selections value but not IE8.

$('input[name="search[gender]"]').change(function()
{
var check = $('input[name="search[gender]"]:checked').val();

Inputs are below:
<input type="radio" name="search[gender]" value="1" class="v_middle" />Male
<input type="radio" name="search[gender]" value="2" class="v_middle" />Female
<input type="radio" name="search[gender]" value="3" class="v_middle" />Couple
<input type="radio" name="search[gender]" value="4" class="v_middle" />tv
<input type="radio" name="search[gender]" value="" checked="checked" class="v_middle" />All

The first time you click a radio button in IE8, no value is returned at all (tested with document.write of the 'check' value), with an error "'null' is null or not an object". The second (and rest of the times) you click any of the checkboxes the wrong value is returned, it returns the value of the currently checked button (which we checked a moment ago) rather than the one we have checked the second time. Does Internet Explorer have issues with this onchange function method? Or is something wrong with my code?

View 1 Replies View Related

Javascript Validation Of Radio, Checkboxes And Text

Jan 18, 2005

I use the following code on a form (which works)

function SubmitDocument(){
var frm=document.forms[0];
if(frm.QuestionSeventeen.value=="") {
alert("Please enter your postcode");
window.document.forms[0].QuestionSeventeen.focus();
return false;
}
else
document.forms[0].submit();
}

This is fine, because QuestionSeventeen is a text field. However, I have a number of radio and checkbox values on my form which I need to make sure are not NULL.

I want to make this more efficient and not use LOTS of these nested IFs.

i.e., does anyone have any code that will check firstly specified text fields, then radio buttons, then checkboxes in a more efficient manner?

so.... somthing like this process is what I want to achieve

Function validate()

- make array of text fields, loop through them checking not null THEN
- make array of checkbox fields, loop through them checking not null THEN
- make array of radio button fields, loop through them checking not null THEN

If all OK, save doc otherwise alert that field needs to be filled in then gocus on that field END FUNCTION

View 15 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved