views:

21

answers:

1

I'm not sure of the best way to do this, I am certain that my JQuery is "clumsy" to say the least but it gets the first part of the job done.

I am dragging "products" to a basket like this:

$j('#basket').droppable({ 
accept: '.productsimg',
drop: function(ev, ui) { 
        $j(this).append(ui.draggable.clone());
        $j("#basket .deleteit").show();
        $j('#basket .instructions').hide();
        $j("#basket .quantityIndicator").show();
        $j("#basket").css("background-image","none");
        $j('#basket .productsimg').removeClass('productsimg');
        $j('#basket .attachment-100x100').css('width','50px');
        $j('#basket .attachment-100x100').css('height','50px');
        $j("#basket .hiddentitle").show();  
        var result = $j('#basket').sortable('toArray');

        alert(result);
        $j('#total').load('/wordpress/wp-content/plugins/shop/test.php');
      } 
});

Yes I am also "manipulating the CSS" after dropping. So far the only way I can "get" the dropped elements ID is to set basket as a sortable like this

$j('#basket').sortable({ 

});

By doing that I can use the "result" alert to see the arrayed ID's - that works, but I am sure it's not right. What doesn't work is when I remove a dropped item from the basket like this:

$j("#basket .deleteit").live('click',function(){
    $j(this).parent().remove();
    var test = $j('#basket').sortable('toArray');
    alert(test);
    var num = $j('#basket .deleteit').length
    if (num == 0) {
       $j('#basket .instructions').show();
       $j("#basket").css("background-image","url(/wordpress/wp-content/plugins/shop/img/cart.png)");
    }
});

What I actually want to happen is the basket array to update. But it doesn't. Any clues please. Thanks. - Oh and please try and keep it "simple" as I am "very simple" at JQuery

+1  A: 

yours is

$j("#basket .deleteit").live('click',function(){ 
     $j(this).parent().remove(); 
     //....some codes..... 
 });

Have you tried,

$j("#basket .deleteit").live('click',function(){ 
    //.... ...some codes... .... 
    $j(this).parent().remove(); 
});

edit: based on your post's comment

var result = $("ul#someId li").map(function(){
   return this.id;
}).get();
// result is now an array containing the id's of li.

demo

Reigel
will `.map()` and `.get()` works on all kinds of dom element... as long as it's a collection... hmmm may i know your `#basket` structure...
Reigel
@Reigel Sorry missed this comment - "will .map() and .get() works", just found it will "simplyfy" #basket for you has images etc and some hidden div's that show when dropped
@Reigel - This is the "bit that drags" - <div class="productsinner"><div class="productsimg" id="<?php the_ID(); ?>"><div class="basketrow" ><img src="/wordpress/wp-content/plugins/shop/img/no.png" alt="Delete" title="Delete" width="16px" height="16px" border="0" class="deleteit" /><?php the_post_thumbnail(array(100,100)); ?><div class="hiddentitle" > <?php the_title(); ?></div><div class="quantityIndicator"><div class="up"></div><div class="testit">1</div><div class="down"></div></div></div></div></div>
And the basket it this - <div class="clearfix" id="basket"><div class="instructions">Drag your purchases to here</div></div>
The JQuery is as originally posted
typo error on my part, "well", not "will", sorry for that... hmmm... I guess you can not use `.map()` and `.get()`... because the structure is changed... if it's just a simple sibling structure(like `li` s), it would be easy... but I guess it's not..
Reigel
Oh forgot, you can see it here - http://molotov.ch/site/?page_id=15
OK I can always change it :) to ul/li's
Oh btw I don't like the "design" so no comments please :)
@Reigel Thanks I have got it working by changing to ul/li's you have been "fantastic"