adding an event to a dynamically added text area, event won't fire

  • Thread starter Nonprofit Programmer
  • Start date
N

Nonprofit Programmer

nI have the below code. I am trying to add the function chgDI() as the
handler for onChage event. However, the reference chgDI(newelement.value), if
in parentheses, is not recognized as a function call. If parentheses are left
out, it is called only when the drawBOX routine is called, and not when the
text area changes. Using addEvent results in a 'mismatch' error. Using
setAttribute doesn't work either. What can I do?

function drawBOX(doit){
if (doit && drawBOXflag == 0) {
drawBOXflag = 1;
var insLOC = document.getElementById("beforeSUBMIT");
var newTEXT =
document.createElement("p"); newTEXT.setAttribute("id","ackTxt");
newTEXT.appendChild(document.createTextNode("Type your message and where
you want it sent"));
insLOC.parentNode.insertBefore(newTEXT,insLOC); var newelement =
document.createElement("textarea"); newelement.setAttribute("id","ackBOX")
newelement.setAttribute("rows","4"); newelement.setAttribute("name","txtAck");
newelement.setAttribute("cols","63");
newelement.setAttribute("value",AMessage); insLOC.parentNode.insertBefore(newelement,insLOC); newelement.attachEvent("ohange",
chgDI(newelement.value)); //Attempt to add Event Handler. - No Luck -
// newelement.setAttribute("onChange" , "chgDI(newelement.value)");
}
else if (!doit && drawBOXflag == 1) {
var delTEXT = document.getElementById("ackTxt");
delTEXT.parentNode.removeChild(delTEXT);
var delBOX = document.getElementById("ackBOX");
delBOX.parentNode.removeChild(delBOX);
drawBOXflag = 0;
}
return
}

function chgDI(DispTXT) {
if (DispTXT !== "") {
alert(DispTXT);
}
}
 

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

Top