Hello friends of my stackoverflow. Today I have problems and need your help to solve them. If you can help with anything, it will be very appreciated! Because I really need to finish this project.
JSFiddle: https://jsfiddle.net/rdxmmobe/1/
This is the script:
<script type="text/javascript"> $(function(){ $(".DraggedItem").draggable({ helper:'clone', cursor:'move', opacity: 0.7 }); $('#rang1').droppable({ drop: function(ev, ui) { $('#rang1input').val($(ui.draggable).attr('id')); var dropped = ui.draggable; var droppedOn = $(this); $(dropped).detach().css({top: 0,left: 0}).appendTo(droppedOn); } }); $('#rang2').droppable({ drop: function(ev, ui) { $('#rang2input').val($(ui.draggable).attr('id')); var dropped = ui.draggable; var droppedOn = $(this); $(dropped).detach().css({top: 0,left: 0}).appendTo(droppedOn); } }); $('#rang3').droppable({ drop: function(ev, ui) { $('#rang3input').val($(ui.draggable).attr('id')); var dropped = ui.draggable; var droppedOn = $(this); $(dropped).detach().css({top: 0,left: 0}).appendTo(droppedOn); } }); $('#rang4').droppable({ drop: function(ev, ui) { $('#rang4input').val($(ui.draggable).attr('id')); var dropped = ui.draggable; var droppedOn = $(this); $(dropped).detach().css({top: 0,left: 0}).appendTo(droppedOn); } }); $('#rang5').droppable({ drop: function(ev, ui) { $('#rang5input').val($(ui.draggable).attr('id')); var dropped = ui.draggable; var droppedOn = $(this); $(dropped).detach().css({top: 0,left: 0}).appendTo(droppedOn); } }); $('#rang6').droppable({ drop: function(ev, ui) { $('#rang6input').val($(ui.draggable).attr('id')); var dropped = ui.draggable; var droppedOn = $(this); $(dropped).detach().css({top: 0,left: 0}).appendTo(droppedOn); } }); $('#rang7').droppable({ drop: function(ev, ui) { $('#rang7input').val($(ui.draggable).attr('id')); var dropped = ui.draggable; var droppedOn = $(this); $(dropped).detach().css({top: 0,left: 0}).appendTo(droppedOn); } }); }); </script>
These are 7 discarded divs (where you can delete images):
<form action="<?php echo $_SERVER["PHP_SELF"] ?>" method="POST"> <input type="hidden" value="<?php echo $row["IDBewoner"] ?>" name="bewoner"> <td> <div id="rang1"></div> <input type="hidden" value="" id="rang1input" name="rang1value"> </td> <td> <div id="rang2"></div> <input type="hidden" value="" id="rang2input" name="rang2value"> </td> <td> <div id="rang3"></div> <input type="hidden" value="" id="rang3input" name="rang3value"> </td> <td> <div id="rang4"></div> <input type="hidden" value="" id="rang4input" name="rang4value"> </td> <td> <div id="rang5"></div> <input type="hidden" value="" id="rang5input" name="rang5value"> </td> <td> <div id="rang6"></div> <input type="hidden" value="" id="rang6input" name="rang6value"> </td> <td> <div id="rang7"></div> <input type="hidden" value="" id="rang7input" name="rang7value"> </td> <input type="submit" value="Save"> </form>
And these are draggable images (images that you can drag and drop), they come from the database and have different identifiers:
<td> <?php echo "<img class='DraggedItem' id='".$row["IDPictogram"]."' src='data:image/jpeg;base64,".base64_encode($row['Pictogram'])."' width='90' height='90' draggable='true'>"; ?> </td>
This is the php code:
if($_SERVER["REQUEST_METHOD"] == "POST") { $rang1 = $_POST["rang1value"]; $rang2 = $_POST["rang2value"]; $rang3 = $_POST["rang3value"]; $rang4 = $_POST["rang4value"]; $rang5 = $_POST["rang5value"]; $rang6 = $_POST["rang6value"]; $rang7 = $_POST["rang7value"]; $bewonerID = $_POST["bewoner"]; echo "<script>alert('Rang1: $rang1')</script>"; echo "<script>alert('Rang2: $rang2')</script>"; echo "<script>alert('Rang3: $rang3')</script>"; echo "<script>alert('Rang4: $rang4')</script>"; echo "<script>alert('Rang5: $rang5')</script>"; echo "<script>alert('Rang6: $rang6')</script>"; echo "<script>alert('Rang7: $rang7')</script>"; }
First problem: As you can see in my script above, I used "helper: 'clone", but the images with the class are ".DraggedItem" and this is not the main thing. Images must be moved and replaced between 7 divs. But they should be cloned from the source list (so that I can use the same icon twice, for example)
Second problem: I have hidden input for each div, and they must contain the id of the discarded image, so I can insert them into the database. Let's say I reset the image to Div1 (# rang1) and then moved the image to Div4 (# rang4), the image identifier remains in the hidden input of Div1 and is not deleted / updated. How can I make sure the identifier is also updated when I drop a new image into a div?
Third problem: how can I perform a check when I delete an image from the main list, what if the image is already there, the old image is deleted and replaced with a new one?

Fourth problem: What is the best way to switch between two images?

If you can help me with any of these problems, it will be very appreciated! I cannot go further without solving these problems, and I really need the help of experts.