In Progress

Order Form w/o Page Refresh

I found this script online. I would like to modify the script to do the same thing, but to allow for more radio button style questions. (Questions where only one answer of a select group is allowed). The current code only works with one radio button set. I would like to have three or more different questions where the user selects answer by clicking a radio button and the value automatically calculates into the total. Code must allow for negative numbers.

<!-- Paste this code into an external JavaScript file -->

/* This script and many more are available free online at

The JavaScript Source :: [url removed, login to view]

Created by: Kevin Hartig :: [url removed, login to view] */

// Calculate the total for items in the form which are selected.

function calculateTotal(inputItem) {

with ([url removed, login to view]) {

// Process each of the different input types in the form.

if ([url removed, login to view] == "radio") { // Process radio buttons.

// Subtract the previously selected radio button value from the total.

[url removed, login to view] = eval([url removed, login to view]) - eval([url removed, login to view]);

// Save the current radio selection value.

[url removed, login to view] = eval([url removed, login to view]);

// Add the current radio button selection value to the total.

[url removed, login to view] = eval([url removed, login to view]) + eval([url removed, login to view]);

} else { // Process check boxes.

if ([url removed, login to view] == false) { // Item was uncheck. Subtract item value from total.

[url removed, login to view] = eval([url removed, login to view]) - eval([url removed, login to view]);

} else { // Item was checked. Add the item value to the total.

[url removed, login to view] = eval([url removed, login to view]) + eval([url removed, login to view]);

}

}

// Total value should never be less than 0.

if ([url removed, login to view] < 0) {

InitForm();

}

// Return total value.

return(formatCurrency([url removed, login to view]));

}

}

// Format a value as currency.

function formatCurrency(num) {

num = [url removed, login to view]().replace(/$|,/g,'');

if(isNaN(num))

num = "0";

sign = (num == (num = [url removed, login to view](num)));

num = [url removed, login to view](num*100+[url removed, login to view]);

cents = num%100;

num = [url removed, login to view](num/100).toString();

if(cents<10)

cents = "0" + cents;

for (var i = 0; i < [url removed, login to view]((num.length-(1+i))/3); i++)

num = [url removed, login to view](0,num.length-(4*i+3)) + ',' + [url removed, login to view](num.length-(4*i+3));

return (((sign)?'':'-') + '$' + num + '.' + cents);

}

// This function initialzes all the form elements to default values.

function InitForm() {

// Reset values on form.

document.selectionForm.total.value='$0';

document.selectionForm.calculatedTotal.value=0;

document.selectionForm.previouslySelectedRadioButton.value=0;

// Set all checkboxes and radio buttons on form to unchecked.

for (i=0; i < [url removed, login to view]; i++) {

if ([url removed, login to view][i].type == 'checkbox' | [url removed, login to view][i].type == 'radio') {

[url removed, login to view][i].checked = false;

}

}

}

<!-- Paste this code into the HEAD section of your HTML document

Change the file name and path to match the one you created -->

<script type="text/javascript" src="yourFileName.js"></script>

<!-- Paste this code into the BODY tag -->

<body onload="InitForm();" onreset="InitForm();">

<!-- Paste this code into the BODY section of your HTML document -->

<div align="center">

<table><tr><td>

<form method="POST" name="selectionForm">

<b>Pizza Order</b><br>

Small $[url removed, login to view]

<input type="checkbox" name="Steak" value="10.00" onclick="this.form.total.value=calculateTotal(this);">

Medium $[url removed, login to view]

<input type="checkbox" name="Chicken" value="12.00" onclick="this.form.total.value=calculateTotal(this);">

Large $[url removed, login to view]

<input type="checkbox" name="Sushi" value="15.00" onclick="this.form.total.value=calculateTotal(this);">

<br><br>

<b>Extra Toppings (only one selection allowed):</b> <br>

<input type="radio" name="Sauce" value="0.00" onclick="this.form.total.value=calculateTotal(this);"> None

<br>

<input name="Sauce" type="radio" value="1.00" onclick="this.form.total.value=calculateTotal(this);"> Extra Cheese $[url removed, login to view]

<br>

<input type="radio" name="Sauce" value="2.00" onclick="this.form.total.value=calculateTotal(this);"> Vegetarian $[url removed, login to view]

<br>

<input type="radio" name="Sauce" value="3.00" onclick="this.form.total.value=calculateTotal(this);"> Meat $[url removed, login to view]

<br>

<br>

<input type="hidden" name="calculatedTotal" value="0">

<input type="hidden" name="previouslySelectedRadioButton" value="0">

<strong>Your total is:</strong>

<input type="text" name="total" readonly onfocus="[url removed, login to view]();">

</form>

</td></tr></table>

</div>

<p><div align="center">

<font face="arial, helvetica" size"-2">Free JavaScripts provided<br>

by <a href="http://javascriptsource.com">The JavaScript Source</a></font>

</div><p>

Skills: Javascript

See more: order total refresh html, javascript radio eval, javascript pizza order form, three p, select group, substring c, style head, src format file, save net online, return path, page free online, online format javascript, numbers function, match page, format code online, group o, function numbers, free radio code, c substring, check javascript code online, calculate online, javascript refresh form total, form checkbox onclick refresh, kevin hartig, javascript pizza form checkbox

About the Employer:
( 3 reviews ) Springfield, United States

Project ID: #193477

Awarded to:

kallukabadi

Hi, Please see your PMB.

$30 USD in 1 day
(5 Reviews)
2.6

6 freelancers are bidding on average $38 for this job

sriramesh

Hi, Please check PM. Thanks & Regards, SriRamesh

$40 USD in 1 day
(12 Reviews)
4.0
jimkoteni

Hello, check PM

$40 USD in 1 day
(0 Reviews)
0.0
jltorres

I can help with your project, I have a dev environment where to show you the result.

$50 USD in 1 day
(0 Reviews)
0.0
Matsiej

This should be pretty easy to do. Contact me if you are interested.

$40 USD in 1 day
(0 Reviews)
0.0
francislow82

Hi there, I am confident of doing this in less than an hour.. Thanks!

$30 USD in 0 days
(0 Reviews)
0.0