Hi Everyone:

I ‘m having a little problem. I currently have a table containing form elements. By default the table has one row. Certain fields need to be numbers so I’m using javascript to validate them. Everything works fine on the original row. I’m using DOM to add rows to the table. But when I try to validate the field to check if it’s a number, the key pad numbers don’t register as numbers any more. It still works on row 1 (the original row) but not the added rows.

Example: when I press the number 1 keypad key and alert the results, on elements of the first row I get a key number of 49, but on elements that were added through DOM I get 97 which is actually ‘A’ not the number 1.


Here’s an example of the code I’m using to add rows to the table

Code:
             var tRow = document.createElement("tr");

             cell = document.createElement("td");
	cell.id = “row_id";
	input = document.createElement("input");
	input.setAttribute("type","textbox");
	input.id="txt";
	input.className="";
	
if(navigator.appName == "Microsoft Internet Explorer")
	{
		input.onkeydown = function(){return onlyNum(event)};
	}
	else
	{
	
	input.setAttribute("onkeydown","return onlyNum(event)");
	}
	cell.appendChild(input);
	tRow.appendChild(cell);
Here’s my number checking function

Code:
function onlyNum(e)
{
	
	var keynum;
	var numcheck = /\d/;
	
	
	
	if(window.event)
	{
		keynum = e.keyCode;
	}
	else
	{
		keynum = e.which;
	}
	
	if((keynum == 0)||(keynum == 8)||(keynum == 46)|| numcheck.test(String.fromCharCode(keynum))) 
	{
	   return true;
    }
    else
    {
 	   return false;
    }
}