Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Javascript
Setting the event handler.
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Prasad, post: 4929348"] 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[i].setAttribute ( "bgcolor", "#FFFFFF" ) ; tbody.rows[i].insertCell(0) ; tSN = document.createElement ( "input" ) ; tSN.type = "text" ; tSN.name ="newSN" ; EventUtil.addEventHandler ( tSN, "keypress", TextUtil.ChekcForSpace ) ; tbody.rows[i].insertCell(1) ; tbody.rows[i].cells[1].appendChild ( tSN ) ; tIP = document.createElement ( "input" ) ; tIP.type = "text" ; tIP.name ="newIP" ; EventUtil.addEventHandler ( tIP, "keypress", TextUtil.ChekcForSpace ) ; tbody.rows[i].insertCell (2) ; tbody.rows[i].cells[2].appendChild ( tIP ) ; tCN = document.createElement ( "input" ) ; tCN.type = "text" ; tCN.name ="newCN" ; EventUtil.addEventHandler ( tCN, "keypress", TextUtil.ChekcForSpace ) ; tbody.rows[i].insertCell (3) ; tbody.rows[i].cells[3].appendChild ( tCN ) ; tCIP = document.createElement ( "input" ) ; tCIP.type = "text" ; tCIP.name ="newCN" ; EventUtil.addEventHandler ( tCIP, "keypress", TextUtil.ChekcForSpace ) ; tbody.rows[i].insertCell (4) ; tbody.rows[i].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.[/i][/i][/i][/i][/i][/i][/i][/i][/i][/i] [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Javascript
Setting the event handler.
Top