Connecting Tech Pros Worldwide Forums | Help | Site Map

OnChange event for dynamic textbox

Newbie
 
Join Date: Feb 2008
Posts: 18
#1: Mar 4 '08
Hi
I m creating a textbox dynamically on click of a button. I want to attach an onChange event for that textbox.I tried using following code but it does not seem to work.Can anyone suggest a better way to solve my problem. The code i am using is as follows:

Expand|Select|Wrap|Line Numbers
  1.  var cell1 = row.insertCell(0);
  2.   var addRowTextNode1 = document.createElement('input');
  3.  addRowTextNode1.setAttribute('type','text','name','UI'+iIteration,'id','UI'+iIteration);
  4. addRowTextNode1.onChange=function callChange(){alert('Hi');};
  5.   cell1.appendChild(addRowTextNode1);
Thanks
daitasri

Newbie
 
Join Date: Feb 2008
Posts: 12
#2: Mar 4 '08

re: OnChange event for dynamic textbox


function CreateBox()
{

var addRowTextNode1 = document.createElement('input');
addRowTextNode1.setAttribute('type','text','name') ;
var x=document.getElementById('form1')

x.appendChild(addRowTextNode1);
myOnChange = new Function("e", "callChange()");
addRowTextNode1.onchange=myOnChange ;


}
function callChange()
{alert('Hi');};

Hope this helps!
Quote:

Originally Posted by daitasri

Hi
I m creating a textbox dynamically on click of a button. I want to attach an onChange event for that textbox.I tried using following code but it does not seem to work.Can anyone suggest a better way to solve my problem. The code i am using is as follows:

Expand|Select|Wrap|Line Numbers
  1.  var cell1 = row.insertCell(0);
  2.   var addRowTextNode1 = document.createElement('input');
  3.  addRowTextNode1.setAttribute('type','text','name','UI'+iIteration,'id','UI'+iIteration);
  4. addRowTextNode1.onChange=function callChange(){alert('Hi');};
  5.   cell1.appendChild(addRowTextNode1);
Thanks
daitasri

rnd me's Avatar
Expert
 
Join Date: Jun 2007
Location: Urbana IL
Posts: 411
#3: Mar 4 '08

re: OnChange event for dynamic textbox


in firefox, you may often find it handy to use

Expand|Select|Wrap|Line Numbers
  1.  elmTextarea.setAttribute("onchange", "alert('function code goes here')"
  2.  
Reply


Similar JavaScript / Ajax / DHTML bytes