tags:

views:

709

answers:

2

Hey!

I'm trying to validate a textarea so a user can't add a new empty message via tinyMCE textarea.

But it just don't seems to work.

What am i doing wrong ?

JS:

var msg = $("#msg");
        if(msg.val() == ''){
             $("#msg_error").html("* Can't add an empty message");
        }

Textarea

<textarea rows="5" cols="35" id="msg"></textarea>
A: 

Yes, i found the solution!!

Here it comes:

var content = tinyMCE.get('msg').getContent(); // msg = textarea id

if( content == "" || content == null){
             $("#msg_error").html("* Can't add an empty message");
        }
william
A: 

the textarea in tinymce is not always purely empty, althuogh you see nothing, tinymce automatically adds html to the textarea. What this means is the textarea will contain html code like

. What you must do is use php's strip tags function to remove html and test for emptiness afterward. Goodluck.

?php $texttostrip =strip_tags($_POST['formdata']); if($texttostrip != "") { echo "Empty Field" }

This would mean using ajax requests to check the data every now and then

thx alot, this answer is useful :)
william