<p><input type=text size="8"> <input type=button value="Факториал!" onclick=initSumF(this)></p>
<script type="text/javascript">
function Factorial(X) {
if (X == 0 || X == 1) return 1;
else return (X * Factorial (X - 1));
}
function SummFact(X) {
var sum = 0;
for(var i =1; i<X+1; i++) {
sum+=Factorial(i);
}
return sum;
}
function initSumF(elem) {
var elem=elem.parentNode.childNodes[0];
if( +elem.value > 170){elem.value="error !";return}
elem.value=SummFact(+elem.value);
}
</script>