Forum Moderators: open
Alternately you could use a server-side language such as ASP, PHP etc. the upside is that the logic is protected but the downside is that you have to send the data off for it to be able to return the answer.
Both examples assume the constant is 100 because I'm lazy!
JAVASCRIPT;Assumes a form called "myform" exists and has three input boxes - "myh", "myw" and "theanswer" (use readonly to make this last one non-editable).
<script type="text/javascript">
function DoCalc(){if( isNaN( document.myform.myh.value ) ¦¦ isNaN( document.myform.myw.value ) ){
alert( "Bad input!" );
}else{
document.myform.theanswer.value = ( document.myform.myh.value.valueOf() * document.myform.myw.value.valueOf() ) * 100;
}
}
</script>
ASP;Assumes a form has passed data to the script via either GET or POST and that it includes two bits of data - "myh" and "myw"
<%
If IsNumeric( Request("myh") ) And IsNumeric( Request("myw") ) ThenResponse.Write "The answer is "
Response.Write ( Request("myh") * Request("myw") ) * 100Else
Response.Write "Bad Data"
End If
%>
- Tony