Hi I've used an old adobe dreamweaver extension called form calculator by Kaosweaver. its made a basic form calculator for me and it works by the customer stating the total number of square metres of tiles they need. The result is the total number of tiles needed for that area.
I then added a check box so the customer can add 10% to the total amount onclick.
however onclick isn't the same as true and false and when the customer unclicks the check box it is seen as a new onclick and adds another 10% instead of removing the first 10%.
(10% is actually *1.1 in the calculation).
Can someone please tell me how I should have the code so the check box performs the way I intend it to work.
Tile Calculator
`enter code here`<script type="text/javascript">
<!--
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document;
if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++)
x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++)
x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function KW_getVal(o){ //v1.2
var retVal="0";if (o.type=="select-one")
{retVal=(o.selectedIndex==-1)?
0:o.options[o.selectedIndex].value;}
else if (o.length>1){for (var i=0;i<o.length;i++) if (o[i].checked) retVal=o[i].value;
} else if (o.type=="checkbox") {retVal=(o.checked)?o.value:0;} else {
retVal=Number(o.value)}return parseFloat(retVal);
}
function KW_calcForm() { //v1.2
var str="",a=KW_calcForm.arguments; for (var i=3;i<a.length;i++)
str+=(a[i].indexOf("#")==-1)?a[i]:KW_getVal(MM_findObj(a[i].substring(1)));
t=Math.ceil(a[1]*eval(str))/a[1];tS=t.toString();if(a[2]>0){tSp=tS.indexOf(".");
if(tSp==-1) tS+=".";tSp=tS.indexOf(".");while(tSp!=(tS.length-1-a[2])){tS+="0";
tSp=tS.indexOf(".");}} MM_findObj(a[0]).value=tS;
}
//-->
</script>
<form id="form1" name="form1" method="post">
<p> <label onclick="KW_calcForm('number of tiles',1,-1,'#square
meters','*','50')">square meters
<input name="square meters" type="text" id="squaremeters"
onkeyup="KW_calcForm('number of tiles',1,-1,'#square
meters','*','50')" />
</label>
</p>
<p>
<label>number of tiles
<input type="text" name="number of tiles" id="numberoftiles"
readonly />
</label>
</p>
Remember! We always recommend to add 10% extra for cuts
<input name="10pecent" type="checkbox" id="myCheck" onClick="KW_calcForm('number of tiles',1,-1,'#number of tiles','*','1.1')" value="plus10percent"> <label>add 10% extra to total.</label>
Aucun commentaire:
Enregistrer un commentaire