Referencing the textbox's data

When I add in for the part in red m=1 it prints out “1” in the textbox so the error must be in the part in red.

<script type=“text/javascript”>
function monthdate(){
var m=number(;
window.document.myform.t.value = m;
<form name=“myform”>
<table><tr><td align=“Center”><INPUT TYPE=“text” NAME=“mo” VALUE=“9” SIZE=“4”></td><INPUT TYPE=“button” NAME=“month” VALUE=“Calculate month” onClick=“monthdate()”/></td><td align=“Center” colspan=“4”><INPUT TYPE=“text” NAME=“t” SIZE = “”></td></tr></table>

This will do it, but you need error handling for out of range numbers and non-number entries. I have removed your number object and replaced it with a parseInt() which does the same job. The short cut to the form just simplifies the code making it more readable. I also needed to add a little to your table.



<script type=“text/javascript”>
// initialise on page load
var form1; // global
function shortCut()
{ form1=window.document.myform;
// -------------
// you need error handling here to cover alpha characters
// and numbers >12 and <1
function monthdate()
{ form1.result.value = parseInt(;

<body onload=“shortCut()”>

<form name=“myform”>
<table border=“0” cellpadding=“0” cellspacing=“0” style=“border-collapse:collapse” width=“300”>
<td><input type=“text” name=“mo” value=“9” SIZE=“4”></td>
<input type=“button” name=“month” value=“Calculate month” onClick=“monthdate()”></td>
<td><input type=“text” name=“result” size=“5”></td>



Please ignore the form there are errors.