views:

481

answers:

3

I'm trying to get the content of a textarea inside a sortable item in jQuery... I can't seem to figure it out! Here's what I have now:

jQuery(document).ready(function() { 
    jQuery("#list").sortable({
        axis : 'y' ,
        revert : 'true' ,
 opacity : 0.5 ,
 stop : function (e, ui) {
  jQuery("input#output"); 
 }
    });        
});

This has to be so simple I'll smack my own head when I find out how to do it, but saying that, I just can't figure it out. Can anyone help?

+1  A: 

EDIT: For a textarea, the "input#output" selector does not work. This only works for a TextBox. To access the contents just add .val()

jQuery(this).children("textarea#output").val(); //for a textarea
jQuery(this).children("input#output").val(); //for a textbox
ichiban
+2  A: 

Just thinking about something you can try (without looking at your html markup)

jQuery(this).children('textarea#output').val();
jQuery(this).children('#output').val(); // this line may be all you need as well
Jon Erickson
the selector with 'input#output' does not work for a TextArea
ichiban
you are correct!
Jon Erickson
I'm actually trying to select the children of the currently active item in the sortable... how do I do that?
Reactor5
+1  A: 

ui in the stop function holds the just moved sortable at ui.item.

ui.item.children("textarea.output").val();  //whatever one you may need.
ui.item.children(".output").val();
ui.item.children("textarea").val();

I also changed "#output" to ".output" because it is standard practice not to have multiple elements with the same id (assuming that there is a textbox with an id of output in each of your sortable items.) If they are similar elements, make them the same class instead.

Ben Koehler
close enough to count, it works great, thanks!
Reactor5