Setting the event handler.

P

Prasad

Hi All,

I have a table displayed. When any one clicks on the ADD button, I want
some text box and combo boxes (select) to get displayed as new row in
the table.
I also want to set event handler for the text boxes on any keypress.

I am able to displaynew row with text boxes. I tried setting
EventHandler but, there is something going wrong.

Please help.

This is the code I have written

function tblAddNewSystem ()
{
var tbody = document.getElementById ( "SysData" ) ;
var i = tbody.rows.length ;
var tSN, tIP, tCN, tCIP, cOS, cMDL, cST, cAT ;

tbody.insertRow ( i ) ;
tbody.rows.setAttribute ( "bgcolor", "#FFFFFF" ) ;
tbody.rows.insertCell(0) ;

tSN = document.createElement ( "input" ) ;
tSN.type = "text" ;
tSN.name ="newSN" ;
EventUtil.addEventHandler ( tSN, "keypress",
TextUtil.ChekcForSpace ) ;
tbody.rows.insertCell(1) ;
tbody.rows.cells[1].appendChild ( tSN ) ;

tIP = document.createElement ( "input" ) ;
tIP.type = "text" ;
tIP.name ="newIP" ;
EventUtil.addEventHandler ( tIP, "keypress",
TextUtil.ChekcForSpace ) ;
tbody.rows.insertCell (2) ;
tbody.rows.cells[2].appendChild ( tIP ) ;

tCN = document.createElement ( "input" ) ;
tCN.type = "text" ;
tCN.name ="newCN" ;
EventUtil.addEventHandler ( tCN, "keypress",
TextUtil.ChekcForSpace ) ;
tbody.rows.insertCell (3) ;
tbody.rows.cells[3].appendChild ( tCN ) ;

tCIP = document.createElement ( "input" ) ;
tCIP.type = "text" ;
tCIP.name ="newCN" ;
EventUtil.addEventHandler ( tCIP, "keypress",
TextUtil.ChekcForSpace ) ;
tbody.rows.insertCell (4) ;
tbody.rows.cells[4].appendChild ( tCIP ) ;
}

TextUtil.ChekcForSpace = function (oEvent)
{
// oEvent = EventUtil.getEvent(oEvent) ;
oEvent = EventUtil.formatEvent (oEvent) ;

// alert ( navigator.appName ) ;
if ( oEvent.keyCode == 32 )
{
alert ( 'Spaces are not allowed.' ) ;
if ( navigator.appName == "Netscape" )
{
oEvent.preventDefault () ;
oEvent.returnValue = false ;
}
else if ( navigator.appName == "Microsoft Internet Explorer" )
{
oEvent.returnValue = false ;
}
return false;
}
return true ;
}

EventUtil.formatEvent = function ( oEvent )
{
if ( navigator.appName == "Microsoft Internet Explorer" )
{
oEvent.charCode = (oEvent.type == "keypress") ?
oEvent.keyCode : 0 ;


oEvent.eventPhase = 2 ;
oEvent.isChar = (oEvent.charCode > 0) ;
oEvent.pageX = oEvent.clientX + document.body.scrollLeft ;
oEvent.pageY = oEvent.clientY + document.body.scrollTop ;
oEvent.preventDefault = function ()
{ this.returnValue = false ; } ;

if ( oEvent.type == "mouseout" )
{
oEvent.relatedTarget = oEvent.toElement ;
}
else if ( oEvent.type = "mouseover" )
{
oEvent.relatedTarget = oEvent.fromElement ;
}

oEvent.stopPropagation = function ()
{ this.cancleBubble = true ; } ;

oEvent.target = oEvent.srcElement ;
oEvent.time = (new Date).gettime () ;
}
return oEvent ;
}

EventUtil.addEventHandler = function ( oTarget, sEventType,
fnHandler )
{
alert ( 'called' ) ;
if ( oTarget.addEventListener )
{
oTarget.addEventListener ( sEventType, fnHandler, false ) ;
}
else if ( oTarget.attachEvent )
{
oTarget.attachEvent ( "on" + sEventType, fnHandler ) ;
}
else
{
oTarget [ "on" + sEventType ] = fnHandler ;
}
}

Please someone help. Thanks in advance.

Thanks and regards,
Prasad.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,571
Members
45,045
Latest member
DRCM

Latest Threads

Top