Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7570117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:20:25+00:00 2026-05-30T15:20:25+00:00

I have picked up this code(DragandDrop.jsp) from this page :: http://jsfiddle.net/petersendidit/S4QgX/ I am getting

  • 0

I have picked up this code(DragandDrop.jsp) from this page ::

http://jsfiddle.net/petersendidit/S4QgX/

I am getting the page like that only.But items are not draggable and i can’t drop them to a particular shopping cart. Seems to me that i have to write an onload() j query function in order to accomplish that for my code in tags, but i don’t know how to that. Or may be there’s another error. I have put css code in the page only rather importing it as an external file. please help me out with the code. Thanks for the help.

DragandDrop.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<style type="text/css">
h1 { padding: .2em; margin: 0; }
#products { float:left; width:200px; height: 600px; margin-right: 20px; }
#products ul {list-style: disc; padding: 1em 0 1em 3em;}
.shoppingCart{ width: 200px; margin: 20px; float: left; }
/* style the list to maximize the droppable hitarea */
.shoppingCart ol { margin: 0; padding: 1em 0 1em 3em; list-style-type: decimal;  }
</style>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
  <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript">

$("#products li").draggable({
    appendTo: "body",
    helper: "clone"
});
$(".shoppingCart ol").droppable({
    activeClass: "ui-state-default",
    hoverClass: "ui-state-hover",
    drop: function(event, ui) {
        var self = $(this);
        self.find(".placeholder").remove();
        var productid = ui.draggable.attr("data-id");
        if (self.find("[data-id=" + productid + "]").length) return;
        $("<li></li>", {
            "text": ui.draggable.text(),
            "data-id": productid
        }).appendTo(this);
        // To remove item from other shopping chart do this
        var cartid = self.closest('.shoppingCart').attr('id');
        $(".shoppingCart:not(#"+cartid+") [data-id="+productid+"]").remove();
    }
}).sortable({
    items: "li:not(.placeholder)",
    sort: function() {
        $(this).removeClass("ui-state-default");
    }
});
</script>
</head>
<body>
<div id="products">
    <h1 class="ui-widget-header">Product list</h1>
    <div class="ui-widget-content">
        <ul>
            <li data-id="1"> product 1 </li>
            <li data-id="2"> product 2 </li>
            <li data-id="3"> product 3 </li>
            <li data-id="4"> product 4 </li>
            <li data-id="5"> product 5 </li>
        </ul>
    </div>
</div>

<div id="shoppingCart1" class="shoppingCart">
    <h1 class="ui-widget-header">Shopping Cart 1</h1>
    <div class="ui-widget-content">
        <ol>
            <li class="placeholder">Add your items here</li>
        </ol>
    </div>
</div>
<div id="shoppingCart2" class="shoppingCart">
    <h1 class="ui-widget-header">Shopping Cart 2</h1>
    <div class="ui-widget-content">
        <ol>
            <li class="placeholder">Add your items here</li>
        </ol>
    </div>
</div>
</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T15:20:26+00:00Added an answer on May 30, 2026 at 3:20 pm

    Put your javascript code in $(document).ready block. As it is now, when your javascript code executes none of the elements are rendered on the page yet, so jQuery has nothing to bind to. $(document).ready will execute only after the page has rendered so your products and shopping cart will be available to jQuery to make them draggable/droppable.

    <script type="text/javascript">
    $(document).ready(function() {
        $("#products li").draggable({
            appendTo: "body",
            helper: "clone"
        });
        $(".shoppingCart ol").droppable({
            activeClass: "ui-state-default",
            hoverClass: "ui-state-hover",
            drop: function(event, ui) {
                var self = $(this);
                self.find(".placeholder").remove();
                var productid = ui.draggable.attr("data-id");
                if (self.find("[data-id=" + productid + "]").length) return;
                $("<li></li>", {
                    "text": ui.draggable.text(),
                    "data-id": productid
                }).appendTo(this);
                // To remove item from other shopping chart do this
                var cartid = self.closest('.shoppingCart').attr('id');
                $(".shoppingCart:not(#"+cartid+") [data-id="+productid+"]").remove();
            }
        }).sortable({
            items: "li:not(.placeholder)",
            sort: function() {
                $(this).removeClass("ui-state-default");
            }
        });
    });
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this bit of code that get the image i have picked from
I have picked up this code from a tutorial and have edited it make
I have picked up this AJAX code from multiple tutorials, but the problem is,
I have picked up this piece of code but as I understand it is
While learning c#, I have picked up the implication from reading other people's code
still fairly new to matlab, picked up this data analysis code from someone and
I have this code (snippet) from a .h file: #import <UIKit/UIKit.h> #import ILView.h /**
Why this code gives me wrong ? In Quick sort , I have picked
In reference with this question We have a header with a date picked component
I have recently picked up a project from a few months ago. Went to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.