tags:

views:

76

answers:

1

--UPDATED--

I want to empty message in a textarea in callback.

Can anyone tell me how to empty it please?

I tried $("#message").empty(), but it does not empty it.

Thanks in advance.

 <form method="post" id="form" action="index.php/admin/messages/insertShoutBox">

    <input name="user" id="nick" value="admin" type="hidden">
    <p class="messagelabel"><label class="messagelabel">Message</label>
    <textarea id="message" name="message" rows="2" cols="40"></textarea>
    <input disabled="disabled" id="send" value="Sending..." type="submit"></p>

</form>

Full code

 $("#form").submit(function(){
    if(checkForm()){
        var nick = inputUser.attr("value");
        var message = inputMessage.attr("value");
        //we deactivate submit button while sending
        $("#send").attr({ disabled:true, value:"Sending..." });
        $("#send").blur();
        //send the post to shoutbox.php
        $.ajax({
            type: "POST", 
            url: "index.php/admin/dashboard/insertShoutBox", 
            data: $('#form').serialize(),
            complete: function(data){
                messageList.html(data.responseText);
                updateShoutbox();
                 $('#message').val('').empty();
                //reactivate the send button
                $("#send").attr({ disabled:false, value:"SUBMIT !" });
            }
         });
    }
    else alert("Please fill all fields!");
    //we prevent the refresh of the page after submitting the form
    return false;
});
+4  A: 

$('#message').val('');

Matt
I tried $('#message').val('').empty(); but did not empty it.
shin
`empty()` does not apply here, that is only used to remove child nodes from an element. `val('')` is correct, so if it is not working, you need to post more code, because it sounds like that specific line is not being called at all
Matt
forget empty(), just use this answer, which sets the value (i.e. contents) of the textarea to nothing.
carillonator
Thanks guys. Solved.
shin
Explanation: `textarea` is an **input** element with a *value*. You actually want to "empty" the *value*. So as for every other input element (`input`, `select`, `textarea`) you need to use `element.val('');`. Also see http://docs.jquery.com/Attributes/val
BalusC