ui.draggable isn't getting pushed into an array and displayed with commas using join

Discussion in 'jQuery' started by makamo66, Nov 18, 2012.

  1. #1
    I want the ids of the draggable divs to show up as a comma separated list in the alert button if they were dropped into the droppable_box. Instead there is an alert for each dragged div one after the other instead of as a list.


    <script type="text/javascript">
    $(document).ready(function(){
    $( "#draggable1" ).draggable({ grid: [ 20,20 ] });
    $( "#draggable2" ).draggable({ grid: [ 20,20 ] });
    $( "#draggable3" ).draggable({ grid: [ 20,20 ] });

    $( "#droppable_box" ).droppable({

    drop: function( event, ui ) {
    var currentId = $(ui.draggable).attr('id');


    var stuff = [];
    $.each($(ui.draggable), function(i,e) {
    stuff.push(e.id);
    });


    var energy = stuff.join(", ");

    var data = "X-Requested-With=XMLHttpRequest";

    $('#myId').click(function(){


    $.post (
    "process.php",
    data,
    function(data)
    {
    alert(energy);

    },
    'html'
    );
    });


    }
    });
    });
    </script>


    In the html there are 3 draggable divs


    <div id="draggable1" class="draggable_meal"></div>
    <div id="draggable2" class="draggable_meal"></div>
    <div id="draggable3" class="draggable_meal"></div>
     
    makamo66, Nov 18, 2012 IP
  2. makamo66

    makamo66 Active Member

    Messages:
    125
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #2
    I changed the jquery a little and published it here:


    http://maureenmoore.com/momp_112412/112412.html


    You can look at the view source. Thanks.
     
    makamo66, Nov 24, 2012 IP
  3. makamo66

    makamo66 Active Member

    Messages:
    125
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #3
    In process.php it gives me 1 to 3 arrays depending on how many divs I dragged. I want to push the $_REQUEST object into an array using


    foreach ($_REQUEST as $key => $value) {
    			array_push($stack,$value);
              }
    print_r($stack);
    
    Code (markup):
    but it gives me 1 to 3 arrays each with the key of zero. How do I get one array out of for example 3 dragged divs?
     
    makamo66, Dec 10, 2012 IP