Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialDanielle Teychenne
3,793 PointsNeed help with a jQuery drag and drop, thankyou ^_^
Hi there, I'm building a super simple drag and drop but my console is telling me that the submit function is not defined.
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>Yay for drap and drops!</title> <script src="http://code.jquery.com/jquery-1.10.2.js"></script> <script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script> <style> div { height: 100px; width: 100px; border: solid 2px #000; margin: 10px; } </style> <script> $(document).ready(function() { $("#correct").draggable(); //I have drag capability now! $("#wrong").draggable(); //I have drag capability now! $("#dropArea1").droppable({ //I drop area capability now! drop: function(event,ui) { var answer = $(ui.draggable).attr("id"); console.log (answer);
}
})
function validate() {
if (answer == ("correct")) {
window.location.replace("http://www.google.com") //correct! redirect web page to next activity
}
else {
window.alert("Incorrect, try again") //incorrect, try again
}
} })
</script> </head> <body> <div id="correct"> <p>CORRECT ANSWER</p> </div>
<div id="wrong"> <p>WRONG ANSWER</p> </div>
<div id="dropArea1"> <p>I'm the drop area</p> </div>
<button onclick="validate()">Submit</button> </body> </html>
1 Answer
Danielle Teychenne
3,793 Points<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Yay for drap and drops!</title>
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<style> div {
height: 100px;
width: 100px;
border: solid 2px #000;
margin: 10px;
}
</style>
<script>
$(document).ready(function() {
$("#correct").draggable(); //I have drag capability now!
$("#wrong").draggable(); //I have drag capability now!
$("#dropArea1").droppable({ //I drop area capability now!
drop: function(event,ui) {
var answer = $(ui.draggable).attr("id");
console.log (answer);
}
})
function validate() {
if (answer == ("correct")) {
window.location.replace("http://www.google.com") //correct! redirect web page to next activity
}
else {
window.alert("Incorrect, try again") //incorrect, try again
}
}
})
</script>
</head>
<body>
<div id="correct">
<p>CORRECT ANSWER</p>
</div>
<div id="wrong">
<p>WRONG ANSWER</p>
</div>
<div id="dropArea1">
<p>I'm the drop area</p>
</div>
<button onclick="validate()">Submit</button>
</body>
</html>
```
Danielle Teychenne
3,793 PointsDanielle Teychenne
3,793 Pointssorry, I forgot to wrap it in backsticks D: