Jump to content

Equivalent to onKeyPress and onKeyDown


dc_jt

Recommended Posts

Hi

Im looking for an equivalent to onKeyPress and onKeyDown to run the following:

[quote]function CheckLength(id)
{
var maxLen = 250;
var curContent = tinyMCE.getContent(id);
var stripped = curContent.replace(/(<([^>]+)>)/ig,"");

stripped = stripped.replace(/&nbsp;/ig," ");

var curLen = stripped.length;

alert(stripped);

if (curLen >= maxLen)
{
var msg = "You have reached your maximum limit of characters allowed";
alert(msg);

//add_edit.description.value = add_edit.description.value.substring(0, maxLen);
}
else
{
document.getElementById('text_num').value = maxLen - curLen;
}
}[/quote]

This is my field in the form:

[quote]<td>Description</td><td>
<textarea onKeyPress="CheckLength(this.id);" onKeyDown="CheckLength(this.id)" id="content" name=description style="width:100%; height:250;" rows="20"><?=(isset($_POST['description']))?$_POST['description']:$aListing['description']?></textarea>
<input size="1" value="250" name="text_num" id="text_num"> Characters Left
<input type="button" onClick="CheckLength('content')" />
</span>
</td>[/quote]

Hope someone can help

Thanks
Link to comment
https://forums.phpfreaks.com/topic/28983-equivalent-to-onkeypress-and-onkeydown/
Share on other sites

[quote author=dc_jt link=topic=116840.msg476307#msg476307 date=1164901317]
Im looking for an equivalent to onKeyPress and onKeyDown...
[/quote]

I'm not sure I follow. [b]Why[/b] is it that you need an equivalent? Can you describe what you're after, and maybe we can help you a little better?

My first impression is that you'd need to simulate a listener to know when your focus is on the textarea. Then, you could use a global key capture to run your function only when the focus is on that element.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.