Setting the event handler.

Discussion in 'Javascript' started by Prasad, Aug 7, 2006.

  1. Prasad

    Prasad Guest

    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.
    Prasad, Aug 7, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sonic
    Replies:
    1
    Views:
    521
    John Saunders
    Jan 7, 2005
  2. Russell Smallwood

    Setting event handler during PostBackEvent

    Russell Smallwood, Feb 23, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    1,464
    Russell Smallwood
    Feb 26, 2005
  3. Replies:
    1
    Views:
    682
    Damien
    Feb 22, 2007
  4. RC

    How to recall add event from an Event handler??

    RC, Jan 6, 2005, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    246
    John Saunders
    Jan 6, 2005
  5. Adi
    Replies:
    2
    Views:
    182
Loading...

Share This Page