PDA

View Full Version : setting dropped attribute into variable



pkcidstudio
10-22-2010, 03:27 AM
See code:

$(function() {
$( "#catalog" ).accordion();
$("#catalog td").livequery(function(){
$(this).draggable({
appendTo: "body",
helper: "clone",
revert: "invalid"
});
});
$( "#cart ol" ).livequery(function(){
$(this).droppable({
activeClass: "ui-state-default",
hoverClass: "ui-state-hover",
accept: ":not(.ui-sortable-helper)",
drop: function( event, ui ) {
$( this ).find( ".placeholder" ).remove();
$( "<li></li>" ).text(ui.draggable.attr('id')).appendTo( this );
//var divIndex = $(this).attr('id');
var droppedId = $(this).ui.draggable.attr('id');
//addToBin(divIndex);
addToBin(droppedId);
}
});
}).livequery(function(){
$(this).sortable({
items: "li:not(.placeholder)",
sort: function() {
// gets added unintentionally by droppable interacting with sortable
// using connectWithSortable fixes this, but doesn't allow you to customize active/hoverClass options
$( this ).removeClass( "ui-state-default" );
}
});});
});

Task: I am trying to grab the attributed id number from the item i drag. everything works fine, except for setting the variable value. Id like to set the variable value = to the attribute value so that I Could run a javascript function to update my database.

this is the part of the code giving me trouble:

var droppedId = $(this).ui.draggable.attr('id');
//addToBin(divIndex);
addToBin(droppedId);


I have a feeling this is something easy but after googling for the better part of the night and trying many different ideas I could not figure out. Thank you in advance for the help everyone.

pkcidstudio
10-22-2010, 01:38 PM
SOLVED: var droppedId = $(ui.draggable).attr("id");