WorkerThread
WorkerThread

Reputation: 13

maintain value of textarea in jquery and php

I am using jquery Datatables and I have a textarea in one column as described at http://www.datatables.net/

The value entered in the textarea is lost when I click on sort in the column header. I did following so far to maintain the value in dtSetup. But the blur event is not working.

 $('#dtSetup input[type=text]').blur(function() {

    txtMessageArr.push([this.id, this.val() ]);


    });

'fnDrawCallback': function() {
    var oTable = $('#dtSetup').dataTable();

    $('input[type=textarea]', oTable.fnGetNodes()).each(function(){
                                    if($.inArray(this.id, txtMessageArr)>=0)
                                            this.value = txtMessageArr[$.inArray(this.id, txtMessageArr)][0];
                                    });


}

Upvotes: 0

Views: 258

Answers (2)

ShankarSangoli
ShankarSangoli

Reputation: 69915

Textarea is another tag and not an input tag, try this

var txtMessageArr = [];

$('#dtSetup textarea').blur(function() {

    txtMessageArr.push([this.id, $(this).html()]);

});

Upvotes: 1

linuxeasy
linuxeasy

Reputation: 6499

this should work:

var txtMessageArr = [];

$('#dtSetup textarea').live('blur',function() {

    txtMessageArr.push([this.id, this.val() ]);

});

When the datatable date is reloaded, all the events attached to is lost. Using live means, it will apply it to all current and future elements matching the selector!

Upvotes: 0

Related Questions