Webocreation

Tuesday, February 1, 2011

Javascript

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

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Untitled Document</title>

<script language="javascript" type="text/javascript">

function calculate(){

var cost=0;

var discount=0;

var total_cost=0;

var flight=0;

for (i=0;i<document.forms[0].a.length;i++) {

if (document.forms[0].a[i].checked) {

cost = document.forms[0].a[i].value;

}

}

for (i=0;i<document.forms[0].b.length;i++) {

if (document.forms[0].b[i].checked) {

discount = document.forms[0].b[i].value;

}

}

if (document.forms[0].c.checked==true) {

flight = document.forms[0].c.value;

}

var total_cost=parseInt(cost)+parseInt(discount*cost/100)+parseInt(flight);

alert(cost+discount+flight+total_cost);



}
</script>

</head>
<body>
<form id="form1" name="form1" method="post" action="">

<table width="600" border="2" cellspacing="0" cellpadding="0">

<tr>

<td>asdf</td>

</tr>

<tr>

<td>ajsdfkj</td>

</tr>

<tr>

<td><p>

<label>

<input type="radio" name="a" value="50" />

tea</label>

<br />

<label>

<input type="radio" name="a" value="100" />

asdf</label>

<br />

<label>

<input type="radio" name="a" value="150" />

asdfasdf</label>

<br />

<label>

<input type="radio" name="a" value="200" />

ewrer</label>

<br />

</p></td>

</tr>

<tr>

<td><p>

<label>

<input type="radio" name="b" value="15" />

ertyer</label>

<br />

<label>

<input type="radio" name="b" value="10" />

kjhgk</label>

<br />

<label>

<input type="radio" name="b" value="5" />

ghjk</label>

<br />

<label>

<input type="radio" name="b" value="0" />

ghjk</label>

<br />

</p></td>

</tr>

<tr>

<td><label>

<input type="checkbox" name="c" value="400" />

</label>

cost 400 </td>

</tr>

<tr>

<td><label>

<input type="submit" name="Submit" value="Calculate" onclick="calculate()" />

</label>

<label>

<input type="reset" name="Submit2" value="Reset" />

</label></td>

</tr>

</table>

</form>
</body>

</html>

No comments:

Post a Comment