简体   繁体   中英

Select from list using jQuery drag and drop

I have items that my php file outputs to a webpage as an unordered list. I want to select these items and then put them into an array.

I would like to use the jQuery drag and drop functionality as seen here in the first answer:

jQuery Sortable - Select and Drag Multiple List Items

and subsequently demonstrated in the fiddle here:

http://jsfiddle.net/T68Fn/

My question is, how do I get the dragged items into an array that I can use with php? Here is the html from the above code:

<div class="demo">
    <p>Available Boxes (click to select multiple boxes)</p>    
    <ul id="draggable">
        <li>Box #1</li>
        <li>Box #2</li>
        <li>Box #3</li>
        <li>Box #4</li>
    </ul>

    <p>My Boxes</p>
    <ul id="droppable">
    </ul>

</div>

Thanks in advance.

Copy the contents of your UL into an input [type=text] field and submit to your PHP script.

In your PHP script you can split your input string into and array on

  • http://php.net/manual/en/function.str-split.php

    You may have to trim and clean up your string a little, but you get the idea.

    Hope this helps.

    Good Luck.

  • The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

     
    粤ICP备18138465号  © 2020-2024 STACKOOM.COM