HTML File
<html xmlns = "http://www.w3.org/1999/xhtml"><head>
<script type="text/javascript">
function bin_to_deci(){
var deciNum=0;
var binaryForm = document.getElementById("binaryForm");
for(i=0; i < binaryForm.elements["binNum"].length; i++)
if(binaryForm.elements["binNum"][i].checked)
deciNum += Math.pow(2, 7-i);
return deciNum;
}
function convert_display(){
var binaryForm = document.getElementById("binaryForm");
binaryForm.deciNum.value = bin_to_deci();
}
</script>
</head><body>
<form id="binaryForm" action="number.php" method="POST">
<h2>Input the binary number</h2>
<p> <input type="checkbox" name="binNum" onchange="convert_display();"/>
<input type="checkbox" name="binNum" onchange="convert_display();"/>
<input type="checkbox" name="binNum" onchange="convert_display();"/>
<input type="checkbox" name="binNum" onchange="convert_display();"/>
<input type="checkbox" name="binNum" onchange="convert_display();"/>
<input type="checkbox" name="binNum" onchange="convert_display();"/>
<input type="checkbox" name="binNum" onchange="convert_display();"/>
<input type="checkbox" name="binNum" onchange="convert_display();"/></p>
<p> Decimal Number :
<input type="text" name="deciNum" size="30" value="0" onfocus="this.blur();"/><br/>
<input type="reset"/><input type="submit"/></p>
</form></body></html>
number.php
file
<html xmlns="http://www.w3.org/1999/xhtml"><body>
<?php
$number = $_POST["deciNum"];
$fp = fopen("record.dat", "a+");
if(flock($fp, LOCK_EX)){
while(!feof($fp)){
$line = fgets($fp);
if($number == intval($line))
return;
}
fwrite($fp, $number . PHP_EOL);
flock($fp, LOCK_UN);
}
fclose($fp);
?></body></html>