Code: Select all
<HTML>
<Head><Title>zakat calculator</Title>
<script type="text/javascript">
function calculate_zakat()
{
// Validate input
allowed = "0123456789.";
obj = eval(document.getElementById("amount"))
for (counter = 0; counter < obj.value.length; counter++)
{
my_char = obj.value.charAt(counter);
if (allowed.indexOf(my_char) == -1)
{
alert("Only Numbers are allowed");
obj.select();
return 1;
}
}
// Calculation of zakat
var t_amount = document.getElementById("amount").value;
var nisab = 2600; // Here we have to write the worth of nisab, which is price of 85-Grams pure gold
var zakat;
if (t_amount >= nisab)
{
zakat= eval(t_amount) * 0.025;
document.getElementById("amount_zakat").value=zakat;
}
else
{
document.getElementById("amount_zakat").value="";
}
}
</script>
</Head>
<Body>
<FORM NAME="frm">
<BR><BR><BR>
<TABLE BORDER="3" ALIGN="center">
<TR>
<TD COLSPAN="2" ALIGN="center">Provide the following information:</TD>
</TR>
<TR>
<TD>Enter Amount: </TD>
<TD><INPUT type="text" id="amount" NAME="amount"></TD>
</TR>
<TR>
<TD>Amount of zakat: </TD>
<TD><INPUT type="text" id="amount_zakat" NAME="amount_zakat"></TD>
<TR>
<TD COLSPAN="2" ALIGN="right">
<INPUT type="button" VALUE="Calculate" onClick="calculate_zakat()">
</TD>
</TR>
</TABLE>
</form>
</Body>
</HTML>