View Full Version : Selecting a radio button to determine a value

05-07-2010, 10:05 PM

I am doing a project, and am need of some help with my code. My assignment is to basically make a program that calculates a household's carbon emissons, in doing this, I have to calculate whether the households cars are running Unleaded, Diesel or LPG fuel for their car...To do this i have made 3 radio buttons (Unleaded , Diesel, LPG). From this i want to be able to determine the amount of fuel used with either Unleaded , Diesel, LPG and then * it by either:

x2.8 Unleaded
x3 Diesel
x1.8 LPG
So thats pretty much where im stuck

If u can help, i'd be more than grateful.


05-08-2010, 12:17 PM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<script type="text/javascript">

function Cal(){
var frm=document.forms[0];
var miles=frm.miles.value=frm.miles.value.replace(/\D/g,'')||0;
var rads=frm.fuel;
for (var z0=0;z0<rads.length;z0++){
if (rads[z0].checked&&miles){
return true;
alert('please select fuel type\nand enter milage');
return false;

x2.8 Unleaded <input type="radio" name="fuel" value="2.8" />
x3 Diesel <input type="radio" name="fuel" value="3" />
x1.8 LPG <input type="radio" name="fuel" value="1.8" />
<br />
Miles <input name="miles" /><br />
Emissons <input name="emissons" /><br />
<input type="button" name="" value="Calculate" onclick="Cal();"/>