Devam Ediyor

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+0.50000000001);

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 $10.00

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

Medium $12.00

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

Large $15.00

<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 $1.00

<br>

<input type="radio" name="Sauce" value="2.00" onclick="this.form.total.value=calculateTotal(this);"> Vegetarian $2.00

<br>

<input type="radio" name="Sauce" value="3.00" onclick="this.form.total.value=calculateTotal(this);"> Meat $3.00

<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>

Beceriler: Javascript

Daha fazlasını görün: order total refresh html, javascript radio eval, javascript pizza order form, subtract previously selected radio button value total, w.o.w. internet, where is w, w-9 questions, three p, the select group, the p.i.c. group, substring in c, substring c, substring 0 2, style your head, src format file, save from net online, return path, p&a group, page free online, online format javascript, o * net online, numbers function, medium com, match page, js format code online

İşveren Hakkında:
( 3 değerlendirme ) Springfield, United States

Proje NO: #193477

Seçilen:

kallukabadi

Hi, Please see your PMB.

1 gün içinde 30$ USD
(5 Değerlendirme)
2.6

6 freelancer bu iş için ortalamada 38$ teklif veriyor

sriramesh

Hi, Please check PM. Thanks & Regards, SriRamesh

1 gün içinde 40$ USD
(12 Değerlendirme)
4.0
jimkoteni

Hello, check PM

1 gün içinde 40$ USD
(0 Değerlendirme)
0.0
jltorres

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

1 gün içinde 50$ USD
(0 Değerlendirme)
0.0
Matsiej

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

1 gün içinde 40$ USD
(0 Değerlendirme)
0.0
francislow82

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

in 0 gün içinde30$ USD
(0 Değerlendirme)
0.0