Online User
Online User

Reputation: 17658

How can I stop the textarea from disappearing?

I have a form that adds comment from the user:

<textarea name="comment" id="comment_box" placeholder="Share your thoughts" cols="175" rows="9"></textarea>     

<input type="button" name="add_comment" id="add_comment_button" value="Add comment" 
 onclick="add_comment_js('comment_form','{$type}')">

Once I click on the button "Add comment" the textarea disappears (I think using jquery), no css files included.

A big functions.js file is linked also, I suspect this method inside the javascript file has to do with the disappearance:

  function add_comment_js(form_id,type)
  {
    var formObjectData = $('#'+form_id).serialize()+'&mode=add_comment';

    $.post(page,formObjectData,
    function(data)
    {
        if(!data)
            alert("No data");
        else
        {
            if(data.cid)
            {
                get_the_comment(data.cid,"#latest_comment_container");
                $("#"+form_id).slideUp();
            }
        }
    },'json');
}

Why is the textarea hiding after I post the comment? What's wrong?

Upvotes: 0

Views: 101

Answers (2)

Brent Waggoner
Brent Waggoner

Reputation: 558

$("#"+form_id).slideUp(); is hiding the form when this function runs. Remove that line and the textarea should persist. Slideup "Hides the matched elements with a sliding motion." Here's the jQuery API reference for that function.

Upvotes: 2

MaK
MaK

Reputation: 606

remove this line form your code

$("#"+form_id).slideUp();

final result should look :

function add_comment_js(form_id,type)
{
    var formObjectData = $('#'+form_id).serialize()+'&mode=add_comment';

    $.post(page,formObjectData,
    function(data)
    {
        if(!data)
            alert("No data");
        else
        {
            if(data.cid)
            {
                get_the_comment(data.cid,"#latest_comment_container");
            }
        }
    },'json');
}

Upvotes: 1

Related Questions