Web Design and Development Forums

ondrop code help needed please

This is a discussion on "ondrop code help needed please" within the JavaScript Forum section. This forum, and the thread "ondrop code help needed please are both part of the Program Your Website category.


Go Back   Webforumz.com > Program Your Website > JavaScript Forum

Welcome to Webforumz.com.
Register Now Register now!

Reply
 
LinkBack Thread Tools Rate Thread
Old May 4th, 2008, 21:55   #1 (permalink)
New Member
 
Join Date: May 2008
Location: England
Posts: 5
ondrop code help needed please

Hi all ... I am trying to write a training piece that will run from my website.

I need help coding ondrop. The user will have four pics and they have to drag a description and drop it under the correct pic.

I have managed to code the drag and drop bit with javascript but cant find any code to help me evaluate the position dropped and give responce. ie correct position or not correct position.

Any help would be gratefully appreciated.
paulf is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old May 4th, 2008, 22:04   #2 (permalink)
Chief Moderator
 
aso186's Avatar
 
Join Date: Oct 2007
Location: UK
Posts: 715
Blog Entries: 2
Send a message via Skype™ to aso186
Re: ondrop code help needed please

You'd probably have to use the onmouseup event (I presume the user has to click and drag whilst holding the button down?)

When the user has released the mouse button, get the position of the element using offsetHeight and offsetWidth.

Then you can compare these results to those of the correct answer position. If they match within X pixels (so the user doesn't have to drop it in the *absolute* correct position), then they've got the answer right!
__________________

aso186 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old May 6th, 2008, 02:49   #3 (permalink)
New Member
 
Join Date: May 2008
Location: England
Posts: 5
Re: ondrop code help needed please

hi aso186 thanks for the reply. i sort of understand the priciple in what you are saying and it makes sence to me but I am not a software engineer by any stretch of the imagination.

this is my code. could you give me an idea of what is required and where it needs to go so that I have a model to work with. I know this is a bit cheeky but it really would help me.

You will see from the code at the end that I need to drop the correct answer below the correct sign.

I know this code doesnt look too elegant but i am more concerned with it being functional than pretty!!

HTML: Select all
<html>
<head>
<link rel="stylesheet" type="text/css" href="setup_style.css">
<title>class</title>
<style type="text/css">
p {margin-left: 90px}
.drag{
position:relative;
cursor:hand;
z-index: 100;
}
</style>
<script type="text/javascript">
/***********************************************
* Drag and Drop Script: © Dynamic Drive (http://www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/
var dragobject={
z: 0, x: 0, y: 0, offsetx : null, offsety : null, targetobj : null, dragapproved : 0,
initialize:function(){
document.onmousedown=this.drag
document.onmouseup=function(){this.dragapproved=0}
},
drag:function(e){
var evtobj=window.event? window.event : e
this.targetobj=window.event? event.srcElement : e.target
if (this.targetobj.className=="drag"){
this.dragapproved=1
if (isNaN(parseInt(this.targetobj.style.left))){this.targetobj.style.left=0}
if (isNaN(parseInt(this.targetobj.style.top))){this.targetobj.style.top=0}
this.offsetx=parseInt(this.targetobj.style.left)
this.offsety=parseInt(this.targetobj.style.top)
this.x=evtobj.clientX
this.y=evtobj.clientY
if (evtobj.preventDefault)
evtobj.preventDefault()
document.onmousemove=dragobject.moveit
}
},
moveit:function(e){
var evtobj=window.event? window.event : e
if (this.dragapproved==1){
this.targetobj.style.left=this.offsetx+evtobj.clientX-this.x+"px"
this.targetobj.style.top=this.offsety+evtobj.clientY-this.y+"px"
return false
}
}
}
dragobject.initialize()
</script>
</head>
<body>
<table border="1" height=15% width=100% align=left bgcolor="#ffffcc">
<td><h3>Cirlular signs give orders. Drag and drop the answer you think best describes each sign.</h3></td>
</table>
 
<br><br><br><br><br><br><br>
<table border="0" width=90% height=5% align=center>
<td><h3><b class="drag">National Speed Limit</b></h3></td>
<td><h3><b class="drag">Max Speed Limit</b></h3></td>
<td><h3><b class="drag">End Min Speed Limit</b></h3></td>
<td><h3><b class="drag">Min Speed Limit</b></h3></td>
</table>
 
<br><br><br><br>
<table border="0" width=80% height=30% align=center>
<td><img src="end min speedlimit.jpg"></td>
<td><img src="min speedlimit.jpg"></td>
<td><img src="national speedlimit.jpg"></td>
<td><img src="40mph.jpg"></td>
</table>
<br>
<table border="0" width=10% align=right>
<form action="unit1_p3.php" method="POST">
<input type="submit" value="NEXT">
</form>
</table>

Last edited by aso186; May 6th, 2008 at 11:19. Reason: Please use [html] tags
paulf is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old May 6th, 2008, 11:21   #4 (permalink)
Chief Moderator
 
aso186's Avatar
 
Join Date: Oct 2007
Location: UK
Posts: 715
Blog Entries: 2
Send a message via Skype™ to aso186
Re: ondrop code help needed please

Will try and have a look Paul, but this really isn't my skill! Hang around and see if a few experts can help you out

Moved to JavaScript Forum
__________________


Last edited by aso186; May 6th, 2008 at 11:24.
aso186 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old May 6th, 2008, 13:24   #5 (permalink)
Nerdy Moderator
 
CloudedVision's Avatar
 
Join Date: Feb 2008
Location: In My Own Little World
Age: 14
Posts: 521
Blog Entries: 4
Re: ondrop code help needed please

I would use mootools for this, it would make programming the drag and drop easier. The beta is very and stable and much better documentation.

Hope that helps.
__________________
Take it easy

Other Road Design

WebForumz Moderator: HTML | Javascript | PHP
CloudedVision is online now  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old May 6th, 2008, 19:56   #6 (permalink)
Moderator
 
spinal007's Avatar
 
Join Date: Mar 2004
Location: Good Ol'London
Age: 22
Posts: 1,609
Blog Entries: 1
Send a message via ICQ to spinal007 Send a message via MSN to spinal007 Send a message via Yahoo to spinal007 Send a message via Skype™ to spinal007
Re: ondrop code help needed please

Since mootools has been suggested, I'll leave my 2 cents: I recommend jQuery. It makes everything in javascript easier, takes care of most cross-browser issue, etc, etc...
Mootools is great, but I think jQuery is easier to learn and more newbie-friendly...
__________________
Diego - SEO Consultant London (My Blog | Fight Me)
jQuery: Star Rating - Multiple File Upload - FCKEditor/Codepress
Before we work on artificial intelligence why don't we do something about natural stupidity?
spinal007 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old May 6th, 2008, 22:12   #7 (permalink)
New Member
 
Join Date: May 2008
Location: England
Posts: 5
Re: ondrop code help needed please

Hi guys thanks to you all for your thought ... I feel important now all the mods replying to me. Unfortunately I am none the wiser about resolving the problem but thanks and I'll take a look at the suggestions
paulf is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old May 7th, 2008, 08:50   #8 (permalink)
Moderator
 
spinal007's Avatar
 
Join Date: Mar 2004
Location: Good Ol'London
Age: 22
Posts: 1,609
Blog Entries: 1
Send a message via ICQ to spinal007 Send a message via MSN to spinal007 Send a message via Yahoo to spinal007 Send a message via Skype™ to spinal007
Re: ondrop code help needed please

aso's suggestion seemed good enough to solve the problem, how did you get on?
__________________
Diego - SEO Consultant London (My Blog | Fight Me)
jQuery: Star Rating - Multiple File Upload - FCKEditor/Codepress
Before we work on artificial intelligence why don't we do something about natural stupidity?
spinal007 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
HTML code for audio player needed Preston HTML Forum 6 Oct 25th, 2007 11:58
live search code and styleswitcher code hebel JavaScript Forum 0 May 12th, 2007 06:16
PHP Code Editor script needed Marc PHP Forum 6 May 5th, 2007 16:31
Simple CGI code needed -urgently- (pleeaasee) coffee Java, JSP, Cold Fusion 1 Aug 16th, 2006 10:48
Can somebody give me the code to hide the source code? renren JavaScript Forum 7 Mar 7th, 2006 12:27



Latest Updates

All Points SEO Security Advisory - CHECK YOUR SITE NOW!

Creative Coding :: February 2008

Webforumz is sponsored by: WESH UK Web Hosting
All times are GMT. The time now is 23:33.

Sleep Study Scoring :: Free Bet :: Website Templates :: Online Betting :: Bookmakers :: Funny Quotes :: Internet Recruitment Software :: Microsoft CRM Experts :: Online Casino :: Decorated Christmas Trees :: Midwife Forums :: Football Betting :: Ecommerce Software :: Web Hosting :: Football Stats :: Dry Cleaning Collection :: xtreme wales - extreme clothing :: Apuestas :: Sharepoint Consultants :: Website Optimisation :: Office Clearance London :: Sharepoint Experts :: Sports Betting :: Casino :: Website Templates :: Web Design Development India :: Online Gambling

Powered by: vBulletin Version 3.7, Copyright ©2000 - 2008, Jelsoft Enterprises Limited.
© 2003-2008 Webforumz.com : All Rights Reserved
Search Engine Friendly URLs by vBSEO 3.2.0 RC6


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59