1 use the # button in the Editor when posting code
2 try the code below
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Title</title>
<style type="text/css">
body{text-align:center;font-family:Georgia,Verdana,Arial;font-size:13px;background:#fff;color:#000;padding:150px 0px 0px 0px;margin:0px 0px 0px 0px;}
input[type="text"]{text-align:center;border:none;background-color:transparent;}
</style>
<script language="javascript" type="text/javascript">
var prices=[
['toilet',70.00],
['sink',50.00],
['shower',445.00],
['copper',3.75]
];
function field(objname){var obj=eval('document.plumbing.'+objname);return obj;}
function chk(obj){
var item=obj.id;
if(!obj.checked){field(item+'_st').value=field(item+'_t').value='0';calc();}
}
function calc(){
var digits=/^[\d]{1,}$/m,a=0,Total=0;
for(var i in prices){
var item=prices[i][0],val=field(item+'_st').value;
if(digits.test(val)){a=parseInt(val)*prices[i][1];}
else{field(item+'_st').value=0;}
field(item+'_t').value=a;
Total+=a;
}
field('total_final').value=Total;
}
function init(){
for(var i in prices){
var item=prices[i][0];
field(item).onclick=function(){chk(this);}
field(item+'_st').onfocus=function(){var k=this.name.substring(0,this.name.indexOf('_')),temp=this.value;this.value=(temp=='0')?'':temp;if(!field(k).checked){field(k).checked=true;}}
field(item+'_st').onblur=function(){var k=this.name.substring(0,this.name.indexOf('_')),temp=this.value;this.value=(temp=='')?'0':temp;field(k).checked=(this.value=='0')?false:true;}
field(item+'_st').onchange=function(){calc();}
}
}
window.onload=init;
</script>
</head>
<body>
<center>
<form name="plumbing" action="">
<table width="750" border="1" cellpadding="3" cellspacing="2">
<tbody>
<tr>
<td width="130">Equipment</td>
<td width="155">Value</td>
<td width="156">Total per item</td>
<td width="289"> </td>
</tr>
<tr>
<td height="95" style="text-align:left">
<input type="checkbox" value="TOILETS" id="toilet" name="toilet" /> Toilet<br />
<input type="checkbox" value="SINKS" id="sink" name="sink" /> Sink<br />
<input type="checkbox" value="SHOWERS" id="shower" name="shower" /> Shower<br />
<input type="checkbox" value="COPPERPIPES" id="copper" name="copper" /> Copper Piping
</td>
<td>
<input name="toilet_st" type="text" value="0" /><br />
<input name="sink_st" type="text" value="0" /><br />
<input name="shower_st" type="text" value="0" /><br />
<input name="copper_st" type="text" value="0" /><br />
</td>
<td>
<input name="toilet_t" type="text" value="0" readonly="readonly" /><br />
<input name="sink_t" type="text" value="0" readonly="readonly" /><br />
<input name="shower_t" type="text" value="0" readonly="readonly" /><br />
<input name="copper_t" type="text" value="0" readonly="readonly" /><br />
</td>
<td> </td>
</tr>
<tr>
<td colspan="3" align="right">Total: </td>
<td><input name="total_final" type="text" value="0" id="total_final" readonly="readonly" /></td>
</tr>
</tbody>
</table>
<div style="margin-top:20px;"><input type="reset" id="Clear" name="Clear" value="Clear" /></div>
</form>
</center>
</body>
</html>
Bookmarks