I use this plugin to count characters on inputs and text areas: http://cssglobe.com/post/7161/jquery-plugin-simplest-twitterlike-dynamic-character-count-for-textareas
I would need to recalculate the characters also in the DIV if the parameter "contentEditable" is set to True.
Is it possible to modify this plugin?
I think I need to change something on this line:
var count = $(obj).val().length;
But I really don't know how contentEditable works ... Any idea?
Thank!
Edit:
I do this as brettz9 suggested:
var method = $.inArray(obj.nodeName.toLowerCase(), ['textarea', 'input']) !== -1 ? 'val' : 'text';
var count = $(obj)[method]().length;
I have only one small problem when doing this for another field that I need to have a minimum / maximum length (I have one input and one contentEditable)
This is the conditional part:
if (other_required){
if ($(other_required).val().length > 0 && available >= 0){
$(submit_button).attr("disabled", "");
} else {
$(submit_button).attr("disabled", "disabled");
}
, [] var "other_required"