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

The Archive Base Latest Questions

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

I’m building a simple puzzle app for and iPad using a JavaScript library for

  • 0

I’m building a simple puzzle app for and iPad using a JavaScript library for dragging and dropping the pieces. I can’t figure out how to check if all the pieces are in the right place however.

What I’ve got so far is

// create the draggable puzzle piece
var p1=document.getElementById('piece1');
new webkit_draggable(p1);
p1.className = 'ps1';

// create an array to count the pieces placed correctly
var countArray = new Array();

// create the dropspot, link it to the puzzle piece and add an element to the array to count. Finally kill the dropspot
var p1p1 = webkit_drop.add('droppiece1',{accept : ['ps1'], onDrop : function(){countArray.push("a");webkit_drop.remove('droppiece1')}});


// piece has been placed correctly.
if(countArray.length = 1){
alert('Piece placed correctly');
};

The problem I’m having is that the alert from the counting function fires immediately.
How can I fix this?

  • 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-31T00:17:21+00:00Added an answer on May 31, 2026 at 12:17 am

    Change your last three lines to:

    // piece has been placed correctly.
    if(countArray.length == 1){
    alert('Piece placed correctly');
    };
    

    You were trying to assign, instead of checking for equality.

    Edit: So, it’s still not working for you? It seems to me you are setting up a listener on onDrop but then directly after you have done that (presumably before the onDrop event ever gets triggered) you are checking if anything has been “dropped”. See how that won’t work?
    If you just want to see that the event is actually getting triggered, and that the “a” is in fact pushed onto your array you could move the last three lines inside your callback. Like so:

    // create the draggable puzzle piece
    var p1 = document.getElementById('piece1');
    new webkit_draggable(p1);
    p1.className = 'ps1';
    
    // create an array to count the pieces placed correctly
    var countArray = new Array();
    
    // create the dropspot, link it to the puzzle piece and add an element to the array to count. Finally kill the dropspot
    var p1p1 = webkit_drop.add('droppiece1', {accept: ['ps1'], onDrop: function() {
        countArray.push("a");
        webkit_drop.remove('droppiece1');
    
        // piece has been placed correctly.
        if (countArray.length == 1) {
            alert('Piece placed correctly');
        }
    }});
    

    I haven’t really tested that, but here is a version with all the webkit stuff taken out and the drop replaced with a simple click: http://jsfiddle.net/kajic/snJMr/1/

    If you click the red box, is that what you expected to happen on your ipad app when you drop the piece?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
I am reading a book about Javascript and jQuery and using one of the
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am using Paperclip to handle profile photo uploads in my app. They upload
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
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

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.