preventDefault() is not working giving object does not support this property
<p>I want to set maximum length of a textbox to 7 and stop further keys entering and using preventDefault but its giving error
My Code is below     </p>

<pre><code>function crInputRK(ctrlid, ControlValue, size, clsName)                                    {

    var newTextBox = crE('input');
    newTextBox.type = 'text';
    newTextBox.style.fontSize = ".9em";
    newTextBox.style['width'] = size;
    newTextBox.style['height'] = '12px';
    newTextBox.style['float'] = 'none';
    newTextBox.style['margin'] = '0 0 0 10px';//added on 13feb2012
    //newTextBox.maxLength = '3';
    newTextBox.id = ctrlid;

    newTextBox.className = 'inputDate';

    //newTextBox.onchange = "javascript:return EnableButton();";

    //ControlValue = getControlValue(ctrlid);
    if (ControlValue != "")
        newTextBox.value = ControlValue;
    if (ControlValue == "Multiple")
        newTextBox.disabled = true;
      newTextBox.setAttribute("onkeypress", "javascript:SetMaxLength(event,this);");


    return newTextBox;
}


function SetMaxLength(e, txtbox)                                                           {

    var MaxLength = 7;
    if (_$(txtbox.id).value.length &gt;= MaxLength) {
        e.preventDefault();

    }
}
</code></pre>
