Brian Hicks
Brian Hicks

Reputation: 6403

Selecting content of a textbox in a sortable, jQuery

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?

Upvotes: 1

Views: 1404

Answers (3)

Ben Koehler
Ben Koehler

Reputation: 8681

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.

Upvotes: 1

Jon Erickson
Jon Erickson

Reputation: 114876

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

Upvotes: 2

ichiban
ichiban

Reputation: 6200

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

Upvotes: 1

Related Questions