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

  • SEARCH
  • Home
  • 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 8490721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:12:29+00:00 2026-06-10T22:12:29+00:00

I’m teaching myself javascript/jquery and decided as a side project to create a drag

  • 0

I’m teaching myself javascript/jquery and decided as a side project to create a drag and drop game. I’ve based it on other tutorials I’ve found and just adapted it really, so go easy on the code – hopefully its not too scary.

I’m using the jquery ui dropable library to implement the game and currently I check once the item is dropped if it is in the correct place, if it is I increment the score by one.

However the problem I have is I can’t get the score to go down by one when the item is dropped in the wrong place.

If a square is placed on the correct placeholder it adds 1 to the score but if that same square gets removed from the correct place holder then it needs to take 1 off the score.

Heres a demo here of what I’ve done so far
http://creativelabel.co.uk/drag-and-drop/

Any ideas?

  • 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-06-10T22:12:31+00:00Added an answer on June 10, 2026 at 10:12 pm

    One way to approach this is to store in the dropped element whether it was placed in a valid square. This means when it is moved to an invalid square you can check if it was previously in a valid one and if this is the case reduce the score by one.

    Hope this is clear!

    See http://jsfiddle.net/pET3y/ for a live demo

    Relevant code:

      if ( slotNumber == imgNumber ) {
        ui.draggable.addClass( 'img-match' );
        ui.draggable.data("valid", true);
    
        imgMatch++;
      }  else {
          if(ui.draggable.data("valid")) {
             imgMatch--;
             ui.draggable.data("valid", false); 
          }
      }
    

    Note: the the fiddle has an alert alert(ui.draggable.data("valid")); for debug

    —

    Changing for on drag the score goes down

    What you do now is listen for the drag event (called activate), and when this is called run a function. The function checks if the element being dragged was previously in the correct position and if it was, marks it as not in the correct position and decreases the score.

    See: http://jsfiddle.net/3NkwJ/1/

          drop: handleDropEvent,
          activate: handleDragEvent //add new event
    } );
    

    And add the below:

      function handleDragEvent( event, ui ) {
        if(ui.draggable.data("valid")) {
                 imgMatch--;
                 $('input[name=Score]').val(imgMatch);
                 $('#score h1').text(imgMatch);
                 ui.draggable.data("valid", false); 
        }      
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am reading a book about Javascript and jQuery and using one of the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

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.