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 1053687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:17:31+00:00 2026-05-16T17:17:31+00:00

I am just learning jquery, so this might be something easy. I am trying

  • 0

I am just learning jquery, so this might be something easy.

I am trying to make a really basic game that you can drop the name of the color onto the color box (to help learn about droppable and draggable).

I got it working except a few problems.

  1. How do I limit the number of items to 1? (Is there a way to check if something is “dropped” onto the box?)

  2. How do I send the data to a php script?

Here is my demo (removed)

Thanks for your help.

========

Ok, I can disable the drop boxes after you drop in into a box. But, if you decided to change you mind I need a reset.

demo2

How do I reset the color names back to the original location?

  • 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-16T17:17:32+00:00Added an answer on May 16, 2026 at 5:17 pm

    Here it is…

    page.html

    <html lang="en">
    <head>
      <meta charset="UTF-8" />
      <title>Color Demo</title>
      <script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
      <script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.4/jquery-ui.min.js"></script>
    
      <style type="text/css">
      #red { background-color: red; }
      #green { background-color: green; }
      #acceptbox1 { background-color: red; width: 150px; height: 170px; padding: 0.5em; float: left; margin: 10px; color: white; font-weight: bold; }
      #acceptbox2 { background-color: green; width: 150px; height: 170px; padding: 0.5em; float: left; margin: 10px; color: white; font-weight: bold; }
      .acceptboxes { width: 150px; height: 170px; padding: 0.5em; float: left; margin: 10px; color: white; font-weight: bold; }
      .colorboxes { width: 100px; height: 20px; padding: 2px; float: left; margin: 2px; border: 2px solid black; cursor: pointer; background-color: white; }
      </style>
      <script type = "text/javascript">
     $(function() {
        var cnt = 0;
     var c1;
     var c2;
        $("#submit, #reset").hide(0);
        $(".colorboxes").draggable({ cursorAt: {cursor: 'move', top: 10, left: 56}, revert: 'invalid',snap: '.ui-widget-header', snapMode: 'inner'});
    
     $("#reset").click(function(){
      cnt=0;
      resetboxes();
     });
     $("#acceptbox1").droppable({
          drop: function(event, ui) {
            $(this).droppable( "option", "disabled", true );
            $(this).addClass('ui-state-highlight').find('p').html("Selected");
      if (!$("#reset").is(":visible")){
       $("#reset").show("blind");
      }
      c1 = ui.draggable.text()
            cnt++;
            checkdrop();
          }
        });
    
        $("#acceptbox2").droppable({
          drop: function(event, ui) {
            $(this).droppable( "option", "disabled", true );
            $(this).addClass('ui-state-highlight').find('p').html("Selected");
            cnt++;
      if (!$("#reset").is(":visible")){
       $("#reset").show("blind");
      }
      c2 = ui.draggable.text()
            checkdrop();
          }
        });
     function checkdrop() {
          if (cnt >= 2) {
            $("#submit").show("blind");
      cnt = 0;
          }
       else {
        $("#submit").hide(0);
       }
        }
    
     $("#submit").click(function(){
      $.ajax({
       url: "program.php",
       type: "GET",
       data: "color1="+c1+"&color2="+c2,
       success: function(msg){
        $("#results").html(msg);
       }
      });
     });
    });
    
    
      function resetboxes() {
        $("#submit, #reset").hide("blind");
     $(".colorboxes").animate({
      position: 'relative',
      left: '0px',
      top: '0px'
     });
        $("#acceptbox1").droppable( "option", "disabled", false ).addClass('ui-state-highlight').find('p').html("");
        $("#acceptbox2").droppable( "option", "disabled", false ).addClass('ui-state-highlight').find('p').html("");
     }
      </script>
    </head>
    <body>
    
    <table border="1">
    <tr>
    <td align="center">
    <div id="acceptbox1">
      <span style="display:none;height:100%;">Unavailable</span>
      <p></p>
    </div>
    </td>
    <td align="center">
    <div id="acceptbox2">
      <span style="display:none;height:100%;">Unavailable</span>
      <p></p>
    </div>
    </td>
    </tr>
    </table>
    <br /><br /><br />
    <div id="colors3" class="colorboxes">
      Red
    </div>
    <div id="colors4" class="colorboxes">
      Green
    </div>
    <div id="colors5" class="colorboxes">
      Blue
    </div>
    <div id="colors6" class="colorboxes">
      Yellow
    </div>
    <br /><br /><br />
    <div id="colors7" class="colorboxes">
      Orange
    </div>
    <div id="colors8" class="colorboxes">
      Purple
    </div>
    <div id="colors9" class="colorboxes">
      Black
    </div>
    <div id="colors10" class="colorboxes">
      Brown
    </div>
    <br /><br /><br />
    
    
    <input type="hidden" value="" name="box1" />
    <input type="hidden" value="" name="box2" />
    
    <input id = "submit" type="submit" value="submit" /><br/>
    <input id = "reset" type="button" value="reset" />
    
    <div id = "results" style = "font-size: 3em;position: relative; top: -7em;left: 9em">
    
    </div>
    </body>
    </html>
    

    program.php

    <?php
        $color1 = $_GET["color1"];
     $color2 = $_GET["color2"];
    
     echo "Color 1: ".$color1.'<br/>'."Color 2:".$color2;
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've just started learning jQuery/javascript, so this might seem like a really basic question,
so I have this jQuery script below that works. But since I'm just learning
I am still learning jQuery and have come up against something I just can't
I'm trying to implement a basic jQuery infinite carousel. As much for the learning
I am currently learning jQuery, and I am curious about something. For functions that
I'm just learning asp.net mvc and I'm trying to figure out how to move
I'm just learning ruby and trying to understand the scope of code executed in
I have just started learning Jquery and am new to writing javascript (I am
I've just started learning Jquery but the examples aren't helping me much... Now whats
I've just starting learning jQuery and AJAX. I'm able to load a local page

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.