What’s causing this error? Should I pass element.value into the function? I know how to set this up in a JSP, but not in JavaScript. I’m having trouble passing values into another function.
function editCommentToggle( id )
{
theRow = document.getElementById("id"+id);
//user = theRow.cells[0].innerHTML;
//date = theRow.cells[1].innerHTML;
com = theRow.cells[2].innerHTML;
idx = 2;
maxlength = 250;
// Comment field
cell = theRow.cells[idx];
while( cell.childNodes.length > 0 )
cell.removeChild(cell.childNodes[0]);
element = document.createElement("textarea");
element.id="comments-"+id;
element.rows="3";
element.value = com;
element.style.width = "400px";
element.maxLength = "250";
element.onfocus = element.onkeydown = element.onkeyup = function(){
return characterCounterEdit(undefined, maxlength, element);
};
cell.appendChild(element);
function characterCounterEdit(id, maxLen, inputElement)
{
spanId = document.getElementById(id);
if (spanId)
{
// Update the counter the user sees.
var whatIsLeft = maxLen - inputElement.value.length;
if ( whatIsLeft < 0 ) whatIsLeft = 0;
spanId.innerText = whatIsLeft;
}
// Restrict user from entering more than the maxlen.
**ERROR HERE-->>>** if ( inputElement.value.length > maxLen )
{
inputElement.value = inputElement.value.substring( 0, maxLen );
}
}
try changing this …
to this …
or you could also try using the event target/sourceElement, described here – http://www.quirksmode.org/js/events_properties.html – in your
characterCounterEditfunction.