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
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.