<html>
<head>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
</head>
<body>
<input type="textbox" value="21" id="m"/><BR>
<input type="textbox" value="6" id="n"/><BR>
<input type="button" value="get GCD" class="calc"/><BR>
<script type="text/javascript">
$("input.calc").click(function(){$("#gcd").html(gcd($("#m").val(),$("#n").val()))});
function gcd(m,n) {
if (n==0) { return m; }
return gcd( n, m % n )
}
function test() {
var data = [
[21, 6, 3],
[15, 10, 5],
[6, 21, 3]
];
$.each(data, function(i, v) {
if (gcd(v[0],v[1]) == v[2]) {
document.write(i, ": test OK<br>");
} else {
document.write(i, ": test NG<BR>");
}
});
}
</script>
GCD is <div id="gcd"/>
<BR>
</body>
</html>