Partage
  • Partager sur Facebook
  • Partager sur Twitter

galère pour un drag and drop!!

Sujet résolu
    14 juin 2009 à 12:38:23

    bonjour!

    je cherche à modifier un script javascript, pour faire glisser une image d'un tableau à un autre.. genre :

    c désigne une case vide (<td></td>)
    les lettres a, b, d... une image (<img scr="a.jep">)

    tableau 1 : tableau 2 :

    a b d e c c c c
    f g h c

    et hop, on choisit l'image b, pour la glisser dans le tableau 2 :

    tableau 1 : tableau 2 :

    a c d e b c c c
    f g h c

    un classique quoi... j'ai trouvé deux scripts sur le net :

    un script super long, mais bien complet...
    null

    et un second, plus simple
    null

    j'ai pu modifier le premier, pour remplacer les contenus des LI par des images et pratiquer dessus pas mal de modif... il me convient plutôt bien, mais les fonctions javascript étant très longues et imbriquées les unes dans les autres... je n'arrive pas à modifier la classe des objets droppables (les LI) pour avoir des objets type image et pouvoir les aligner aussi horizontalement (les li conditionnent bien le fait que les case droppables s'enchainent de haut en bas non?)
    et pareil, idéalement, j'aimerai pouvoir modifier les cases receveuses, pour avoir une ligne horizontale...

    je pensais bien modifier le style et faire une usine à gaz pour obtenir mon resultat (genre alligner les ul receveuses les unes à cotés des autres, pour obtenir une ligne...) mais... j'aurais espéré comprendre le script.. là, il est très long, j'ai identifié ce que faisait les fonction, mais comme je débute dans le javascript, je galère, c'est encore flou...

    le second exemple, plus simple.... me bloque car il concerne des images et des zones délimitées.. je l'ai compris, mais je n'arrive pas à l'adapter pour des div, li, img ou td...

    en fait, je voudrais avoir un exemple vraiment simple, limite deux tableau avec une case dans chacun, et une seule image à bouger, pour identifier la partie "brute" du code permettant le drag and drop... enfin voila, si vous avez un lien vers un code simple ou un truc qui traine dans un de vos premier fichier js.. je prends! :euh:
    • Partager sur Facebook
    • Partager sur Twitter
      14 juin 2009 à 21:22:29

      Pourrais-tu dessiner (ou expliquer longuement ^^ ) le résultat que tu cherches à obtenir concrètement ?

      Parce que là j'ai pas tout compris...
      • Partager sur Facebook
      • Partager sur Twitter
        14 juin 2009 à 23:02:51

        et hop, avec les crayons de couleurs de ma soeur!

        Image utilisateur

        je mets là, la part de mon code qui ne me pose pas de soucis (sans l'avoir développé, c'est pour donner plus d'infos). Pour la partie HTML ça ira, sans soucis, le hic, c'est javascript.. je vais mettre à la suite ce que j'ai trouvé pour le moment, mais il n'y a rien de bien hiérarchisé pour le moment, c'est la part que je ne comprends pas, comem j'expliquais :s

        donc, pour l'html....
        <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
        <html>
        <head>
        	<link rel="stylesheet" media="screen" type="text/css" title="style" href="image_glisser.css" />
        	
        	
        	<script type="text/javascript">
        	
        	//gros soucis ^.^
        	
        	
        	</script>
        <head>	
        
        <body>
        <table id="fruit_legume">
        <tr><td><img id="tomate" src="tomate.jpg"></td>
        	<td><img id="raisin" src="raisin.jpg"></td>
        	<td><img id="banane" src="banane.jpg"></td>
        </tr>
        <tr><td><img id="carotte" src="carotte.jpg"></td>
        	<td></td>
        	<td></td>
        </tr>
        </table>
        
        
        <table id="assiette">
        <tr><td></td>
        	<td></td>
        	<td></td>
        </tr>
        </table>
        	
        </body>
        


        alors, j'ai bien compris qu'il y avait trois étapes :
        * au moment où on clique sur l'image que l'on veut bouger
        => function debutdragdrop () déclanchée par un "onmousedown"

        * quand on déplace l'image
        => function pendantdragdrop () déclanchée par un "onmousemouse"

        * au moment où on dépose l'image dans la case
        => function findragdrop () déclanchée par un "onmouseup"
        • Partager sur Facebook
        • Partager sur Twitter
          15 juin 2009 à 0:01:50

          En utilisant un tableau j'ai réussi à faire quelque chose qui ressemble à ce que tu veux.

          Voici les modifications principales que j'ai apportées au code de la page d'exemple :

          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
          <html>
          <head>
          	<title>Drag and Drop to the columns</title>
          	<style type="text/css">
          	body{
          		font-family: Trebuchet MS, Lucida Sans Unicode, Arial, sans-serif;	/* Font to use */
          		background-color:#E2EBED;
          	}
          	#footer{
          		height:30px;
          		vertical-align:middle;
          		text-align:right;
          		clear:both;
          		padding-right:3px;
          		background-color:#317082;
          		margin-top:2px;
          		width:790px;
          	}
          	#footer form{
          		margin:0px;
          		margin-top:2px;
          	}
          	#dhtmlgoodies_dragDropContainer{	/* Main container for this script */
          		width:790px;
          		height:720px;
          		border:1px solid #317082;
          		background-color:#FFF;
          		-moz-user-select:none;
          	}
          	#dhtmlgoodies_dragDropContainer ul{	/* General rules for all <ul> */
          		margin-top:0px;
          		margin-left:0px;
          		margin-bottom:0px;
          		padding:2px;
          	}
          	
          	#dhtmlgoodies_dragDropContainer li,#dragContent li,li#indicateDestination{	/* Movable items, i.e. <LI> */
          		list-style-type:none;
          		height:30px;
          		background-color:#EEE;
          		border:1px solid #000;
          		padding:2px;
          		margin-bottom:2px;
          		cursor:pointer;
          		font-size:0.9em;
          	}
          	
          	li#indicateDestination{	/* Box indicating where content will be dropped - i.e. the one you use if you don't use arrow */
          		border:1px dotted #600;	
          		background-color:#FFF;
          	}
          
          	
          	/* LEFT COLUMN CSS */
          	div#dhtmlgoodies_listOfItems{	/* Left column "Available students" */
          		
          		float:left;
          		padding-left:10px;
          		padding-right:10px;
          		
          		/* CSS HACK */
          		width: 180px;	/* IE 5.x */
          		width/* */:/**/160px;	/* Other browsers */
          		width: /**/160px;
          				
          	}
          	#dhtmlgoodies_listOfItems ul{	/* Left(Sources) column <ul> */
          		height:560px;	
          
          	}
          		
          	div#dhtmlgoodies_listOfItems div{
          		border:1px solid #999;		
          	}
          	div#dhtmlgoodies_listOfItems div ul{	/* Left column <ul> */
          		margin-left:10px;	/* Space at the left of list - the arrow will be positioned there */
          	}
          	#dhtmlgoodies_listOfItems div p{	/* Heading above left column */
          		margin:0px;	
          		font-weight:bold;
          		padding-left:12px;
          		background-color:#317082;	
          		color:#FFF;
          		margin-bottom:5px;
          	}
          	/* END LEFT COLUMN CSS */
          	
          	#dhtmlgoodies_dragDropContainer .mouseover{	/* Mouse over effect DIV box in right column */
          		background-color:#E2EBED;
          		border:1px solid #317082;
          	}
          	
          	/* Start main container CSS */
          	
          	div#dhtmlgoodies_mainContainer{	/* Right column DIV */
          		width:590px;
          		float:left;	
          	}
          	#dhtmlgoodies_mainContainer div{	/* Parent <div> of small boxes */
          		float:left;
          		margin-right:10px;
          		margin-bottom:10px;
          		margin-top:0px;
          		border:1px solid #999;
          
          		/* CSS HACK */
          		width: 172px;	/* IE 5.x */
          		width/* */:/**/170px;	/* Other browsers */
          		width: /**/170px;
          				
          	}
          	#dhtmlgoodies_mainContainer div ul{
          		margin-left:10px;
          	}
          	
          	#dhtmlgoodies_mainContainer div p{	/* Heading above small boxes */
          		margin:0px;
          		padding:0px;
          		padding-left:12px;
          		font-weight:bold;
          		background-color:#317082;	
          		color:#FFF;	
          		margin-bottom:5px;
          	}
          	
          	#dhtmlgoodies_mainContainer ul{	/* Small box in right column ,i.e <ul> */
          		text-align:center;
          		width:40px;
          		height:80px;	
          		border:0;	
          		margin-bottom:0px;
          		overflow:hidden;
          		
          	}
          	#dhtmlgoodies_mainContainer table {
          		border-collapse:collapse;
          		float:left;
          		margin-left:40px;
          	}
          	#dhtmlgoodies_mainContainer td {
          		border:1px solid red;
          	}
          	
          	#dragContent{	/* Drag container */
          		position:absolute;
          		text-align:center;
          		width:40px;
          		height:30px;
          		display:none;
          		margin:0px;
          		padding:0px;
          		z-index:2000;
          	}
          
          	#dragDropIndicator{	/* DIV for the small arrow */
          		position:absolute;
          		width:7px;
          		height:10px;
          		display:none;
          		z-index:1000;
          		margin:0px;
          		padding:0px;
          	}
          	</style>
          	<style type="text/css" media="print">
          	div#dhtmlgoodies_listOfItems{
          		display:none;
          	}
          	body{
          		background-color:#FFF;
          	}
          	img{
          		display:none;
          	}
          	#dhtmlgoodies_dragDropContainer{
          		border:0px;
          		width:100%;
          	}
          	p{
          		margin-bottom:0px;
          	}	
          	</style>	
          	<script type="text/javascript">
          	/************************************************************************************************************
          	(C) www.dhtmlgoodies.com, November 2005
          	
          	Update log:
          	
          	December 20th, 2005 : Version 1.1: Added support for rectangle indicating where object will be dropped
          	January 11th, 2006: Support for cloning, i.e. "copy & paste" items instead of "cut & paste"
          	January 18th, 2006: Allowing multiple instances to be dragged to same box(applies to "cloning mode")
          	
          	This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website.	
          	
          		Terms of use:
          	You are free to use this script as long as the copyright message is kept intact. However, you may not
          	redistribute, sell or repost it without our permission.
          	
          	Thank you!
          	
          	www.dhtmlgoodies.com
          	Alf Magne Kalleland
          	
          	************************************************************************************************************/
          		
          	/* VARIABLES YOU COULD MODIFY */
          	var boxSizeArray = [1,1,1,1,1,1,1,1];	// Array indicating how many items there is rooom for in the right column ULs
          	
          	var arrow_offsetX = -5;	// Offset X - position of small arrow
          	var arrow_offsetY = 0;	// Offset Y - position of small arrow
          	
          	var arrow_offsetX_firefox = -6;	// Firefox - offset X small arrow
          	var arrow_offsetY_firefox = -13; // Firefox - offset Y small arrow
          	
          	var verticalSpaceBetweenListItems = 3;	// Pixels space between one <li> and next	
          											// Same value or higher as margin bottom in CSS for #dhtmlgoodies_dragDropContainer ul li,#dragContent li
          	
          											
          	var indicateDestionationByUseOfArrow = false;	// Display arrow to indicate where object will be dropped(false = use rectangle)
          
          	var cloneSourceItems = false;	// Items picked from main container will be cloned(i.e. "copy" instead of "cut").	
          	var cloneAllowDuplicates = true;	// Allow multiple instances of an item inside a small box(example: drag Student 1 to team A twice
          	
          	/* END VARIABLES YOU COULD MODIFY */
          	
          	var dragDropTopContainer = false;
          	var dragTimer = -1;
          	var dragContentObj = false;
          	var contentToBeDragged = false;	// Reference to dragged <li>
          	var contentToBeDragged_src = false;	// Reference to parent of <li> before drag started
          	var contentToBeDragged_next = false; 	// Reference to next sibling of <li> to be dragged
          	var destinationObj = false;	// Reference to <UL> or <LI> where element is dropped.
          	var dragDropIndicator = false;	// Reference to small arrow indicating where items will be dropped
          	var ulPositionArray = new Array();
          	var mouseoverObj = false;	// Reference to highlighted DIV
          	
          	var MSIE = navigator.userAgent.indexOf('MSIE')>=0?true:false;
          	var navigatorVersion = navigator.appVersion.replace(/.*?MSIE (\d\.\d).*/g,'$1')/1;
          
          	
          	var indicateDestinationBox = false;
          	function getTopPos(inputObj)
          	{		
          	  var returnValue = inputObj.offsetTop;
          	  while((inputObj = inputObj.offsetParent) != null){
          	  	if(inputObj.tagName!='HTML')returnValue += inputObj.offsetTop;
          	  }
          	  return returnValue;
          	}
          	
          	function getLeftPos(inputObj)
          	{
          	  var returnValue = inputObj.offsetLeft;
          	  while((inputObj = inputObj.offsetParent) != null){
          	  	if(inputObj.tagName!='HTML')returnValue += inputObj.offsetLeft;
          	  }
          	  return returnValue;
          	}
          		
          	function cancelEvent()
          	{
          		return false;
          	}
          	function initDrag(e)	// Mouse button is pressed down on a LI
          	{
          		if(document.all)e = event;
          		var st = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
          		var sl = Math.max(document.body.scrollLeft,document.documentElement.scrollLeft);
          		
          		dragTimer = 0;
          		dragContentObj.style.left = e.clientX + sl + 'px';
          		dragContentObj.style.top = e.clientY + st + 'px';
          		contentToBeDragged = this;
          		contentToBeDragged_src = this.parentNode;
          		contentToBeDragged_next = false;
          		if(this.nextSibling){
          			contentToBeDragged_next = this.nextSibling;
          			if(!this.tagName && contentToBeDragged_next.nextSibling)contentToBeDragged_next = contentToBeDragged_next.nextSibling;
          		}
          		timerDrag();
          		return false;
          	}
          	
          	function timerDrag()
          	{
          		if(dragTimer>=0 && dragTimer<10){
          			dragTimer++;
          			setTimeout('timerDrag()',10);
          			return;
          		}
          		if(dragTimer==10){
          			
          			if(cloneSourceItems && contentToBeDragged.parentNode.id=='allItems'){
          				newItem = contentToBeDragged.cloneNode(true);
          				newItem.onmousedown = contentToBeDragged.onmousedown;
          				contentToBeDragged = newItem;
          			}
          			dragContentObj.style.display='block';
          			dragContentObj.appendChild(contentToBeDragged);
          		}
          	}
          	
          	function moveDragContent(e)
          	{
          		if(dragTimer<10){
          			if(contentToBeDragged){
          				if(contentToBeDragged_next){
          					contentToBeDragged_src.insertBefore(contentToBeDragged,contentToBeDragged_next);
          				}else{
          					contentToBeDragged_src.appendChild(contentToBeDragged);
          				}	
          			}
          			return;
          		}
          		if(document.all)e = event;
          		var st = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
          		var sl = Math.max(document.body.scrollLeft,document.documentElement.scrollLeft);
          		
          		
          		dragContentObj.style.left = e.clientX + sl + 'px';
          		dragContentObj.style.top = e.clientY + st + 'px';
          		
          		if(mouseoverObj)mouseoverObj.className='';
          		destinationObj = false;
          		dragDropIndicator.style.display='none';
          		if(indicateDestinationBox)indicateDestinationBox.style.display='none';
          		var x = e.clientX + sl;
          		var y = e.clientY + st;
          		var width = dragContentObj.offsetWidth;
          		var height = dragContentObj.offsetHeight;
          		
          		var tmpOffsetX = arrow_offsetX;
          		var tmpOffsetY = arrow_offsetY;
          		if(!document.all){
          			tmpOffsetX = arrow_offsetX_firefox;
          			tmpOffsetY = arrow_offsetY_firefox;
          		}
          
          		for(var no=0;no<ulPositionArray.length;no++){
          			var ul_leftPos = ulPositionArray[no]['left'];	
          			var ul_topPos = ulPositionArray[no]['top'];	
          			var ul_height = ulPositionArray[no]['height'];
          			var ul_width = ulPositionArray[no]['width'];
          			
          			if((x+width) > ul_leftPos && x<(ul_leftPos + ul_width) && (y+height)> ul_topPos && y<(ul_topPos + ul_height)){
          				var noExisting = ulPositionArray[no]['obj'].getElementsByTagName('LI').length;
          				if(indicateDestinationBox && indicateDestinationBox.parentNode==ulPositionArray[no]['obj'])noExisting--;
          				if(noExisting<boxSizeArray[no-1] || no==0){
          					dragDropIndicator.style.left = ul_leftPos + tmpOffsetX + 'px';
          					var subLi = ulPositionArray[no]['obj'].getElementsByTagName('LI');
          					
          					var clonedItemAllreadyAdded = false;
          					if(cloneSourceItems && !cloneAllowDuplicates){
          						for(var liIndex=0;liIndex<subLi.length;liIndex++){
          							if(contentToBeDragged.id == subLi[liIndex].id)clonedItemAllreadyAdded = true;
          						}
          						if(clonedItemAllreadyAdded)continue;
          					}
          					
          					for(var liIndex=0;liIndex<subLi.length;liIndex++){
          						var tmpTop = getTopPos(subLi[liIndex]);
          						if(!indicateDestionationByUseOfArrow){
          							if(y<tmpTop){
          								destinationObj = subLi[liIndex];
          								indicateDestinationBox.style.display='block';
          								subLi[liIndex].parentNode.insertBefore(indicateDestinationBox,subLi[liIndex]);
          								break;
          							}
          						}else{							
          							if(y<tmpTop){
          								destinationObj = subLi[liIndex];
          								dragDropIndicator.style.top = tmpTop + tmpOffsetY - Math.round(dragDropIndicator.clientHeight/2) + 'px';
          								dragDropIndicator.style.display='block';
          								break;
          							}	
          						}					
          					}
          					
          					if(!indicateDestionationByUseOfArrow){
          						if(indicateDestinationBox.style.display=='none'){
          							indicateDestinationBox.style.display='block';
          							ulPositionArray[no]['obj'].appendChild(indicateDestinationBox);
          						}
          						
          					}else{
          						if(subLi.length>0 && dragDropIndicator.style.display=='none'){
          							dragDropIndicator.style.top = getTopPos(subLi[subLi.length-1]) + subLi[subLi.length-1].offsetHeight + tmpOffsetY + 'px';
          							dragDropIndicator.style.display='block';
          						}
          						if(subLi.length==0){
          							dragDropIndicator.style.top = ul_topPos + arrow_offsetY + 'px'
          							dragDropIndicator.style.display='block';
          						}
          					}
          					
          					if(!destinationObj)destinationObj = ulPositionArray[no]['obj'];
          					mouseoverObj = ulPositionArray[no]['obj'].parentNode;
          					mouseoverObj.className='mouseover';
          					return;
          				}
          			}
          		}
          	}
          	
          	/* End dragging 
          	Put <LI> into a destination or back to where it came from.
          	*/	
          	function dragDropEnd(e)
          	{
          		if(dragTimer==-1)return;
          		if(dragTimer<10){
          			dragTimer = -1;
          			return;
          		}
          		dragTimer = -1;
          		if(document.all)e = event;	
          		
          		
          		if(cloneSourceItems && (!destinationObj || (destinationObj && (destinationObj.id=='allItems' || destinationObj.parentNode.id=='allItems')))){
          			contentToBeDragged.parentNode.removeChild(contentToBeDragged);
          		}else{	
          			
          			if(destinationObj){
          				if(destinationObj.tagName=='UL'){
          					destinationObj.appendChild(contentToBeDragged);
          				}else{
          					destinationObj.parentNode.insertBefore(contentToBeDragged,destinationObj);
          				}
          				mouseoverObj.className='';
          				destinationObj = false;
          				dragDropIndicator.style.display='none';
          				if(indicateDestinationBox){
          					indicateDestinationBox.style.display='none';
          					document.body.appendChild(indicateDestinationBox);
          				}
          				contentToBeDragged = false;
          				return;
          			}		
          			if(contentToBeDragged_next){
          				contentToBeDragged_src.insertBefore(contentToBeDragged,contentToBeDragged_next);
          			}else{
          				contentToBeDragged_src.appendChild(contentToBeDragged);
          			}
          		}
          		contentToBeDragged = false;
          		dragDropIndicator.style.display='none';
          		if(indicateDestinationBox){
          			indicateDestinationBox.style.display='none';
          			document.body.appendChild(indicateDestinationBox);
          			
          		}
          		mouseoverObj = false;
          		
          	}
          	
          	/* 
          	Preparing data to be saved 
          	*/
          	function saveDragDropNodes()
          	{
          		var saveString = "";
          		var uls = dragDropTopContainer.getElementsByTagName('UL');
          		for(var no=0;no<uls.length;no++){	// LOoping through all <ul>
          			var lis = uls[no].getElementsByTagName('LI');
          			for(var no2=0;no2<lis.length;no2++){
          				if(saveString.length>0)saveString = saveString + ";";
          				saveString = saveString + uls[no].id + '|' + lis[no2].id;
          			}	
          		}		
          		
          		document.getElementById('saveContent').innerHTML = '<h1>Ready to save these nodes:</h1> ' + saveString.replace(/;/g,';<br>') + '<p>Format: ID of ul |(pipe) ID of li;(semicolon)</p><p>You can put these values into a hidden form fields, post it to the server and explode the submitted value there</p>';
          		
          	}
          	
          	function initDragDropScript()
          	{
          		dragContentObj = document.getElementById('dragContent');
          		dragDropIndicator = document.getElementById('dragDropIndicator');
          		dragDropTopContainer = document.getElementById('dhtmlgoodies_dragDropContainer');
          		document.documentElement.onselectstart = cancelEvent;;
          		var listItems = dragDropTopContainer.getElementsByTagName('LI');	// Get array containing all <LI>
          		var itemHeight = false;
          		for(var no=0;no<listItems.length;no++){
          			listItems[no].onmousedown = initDrag;
          			listItems[no].onselectstart = cancelEvent;
          			if(!itemHeight)itemHeight = listItems[no].offsetHeight;
          			if(MSIE && navigatorVersion/1<6){
          				listItems[no].style.cursor='hand';
          			}			
          		}
          		
          		var mainContainer = document.getElementById('dhtmlgoodies_mainContainer');
          		var uls = mainContainer.getElementsByTagName('UL');
          		itemHeight = itemHeight + verticalSpaceBetweenListItems;
          		for(var no=0;no<uls.length;no++){
          			uls[no].style.height = itemHeight * boxSizeArray[no]  + 'px';
          		}
          		
          		/*var leftContainer = document.getElementById('dhtmlgoodies_listOfItems');
          		var itemBox = leftContainer.getElementsByTagName('UL')[0];*/
          		
          		document.documentElement.onmousemove = moveDragContent;	// Mouse move event - moving draggable div
          		document.documentElement.onmouseup = dragDropEnd;	// Mouse move event - moving draggable div
          		
          		var ulArray = dragDropTopContainer.getElementsByTagName('UL');
          		for(var no=0;no<ulArray.length;no++){
          			ulPositionArray[no] = new Array();
          			ulPositionArray[no]['left'] = getLeftPos(ulArray[no]);	
          			ulPositionArray[no]['top'] = getTopPos(ulArray[no]);	
          			ulPositionArray[no]['width'] = ulArray[no].offsetWidth;
          			ulPositionArray[no]['height'] = ulArray[no].clientHeight;
          			ulPositionArray[no]['obj'] = ulArray[no];
          		}
          		
          		if(!indicateDestionationByUseOfArrow){
          			indicateDestinationBox = document.createElement('LI');
          			indicateDestinationBox.id = 'indicateDestination';
          			indicateDestinationBox.style.display='none';
          			document.body.appendChild(indicateDestinationBox);
          
          			
          		}
          	}
          	
          	window.onload = initDragDropScript;
          	</script>
          
          </head>
          <body>
          <div id="dhtmlgoodies_dragDropContainer">
            <div id="dhtmlgoodies_mainContainer">
              <table id="tab6">
                <tr>
                  <td>
                    <ul><li><img src="http://www.siteduzero.com/Templates/images/designs/2/tutos/cat_siteweb.png" /></li></ul>
                  </td>
                  <td>
                    <ul><li><img src="http://www.siteduzero.com/Templates/images/designs/2/tutos/cat_prog.png" /></li></ul>
                  </td>
                  <td>
                    <ul><li><img src="http://www.siteduzero.com/Templates/images/designs/2/tutos/cat_os.png" /></li></ul>
                  </td>
                </tr>
                <tr>
                  <td>
                    <ul><li><img src="http://www.siteduzero.com/Templates/images/designs/2/tutos/cat_3d.png" /></li></ul>
                  </td>
                  <td>
                    <ul></ul>
                  </td>
                  <td>
                    <ul></ul>
                  </td>
                </tr>
              </table>
              <table id="tab2">
                <tr>
                  <td>
                    <ul></ul>
                  </td>
                  <td>
                    <ul></ul>
                  </td>
                </tr>
              </table>
            </div>
          </div>
          <div id="footer">
          	<form action="aPage.html" method="post"><input type="button" onclick="saveDragDropNodes()" value="Save"></form>
          </div>
          <ul id="dragContent"></ul>
          <div id="dragDropIndicator"><img src="" /></div>
          <div id="saveContent"></div>
          	</body>
          </html>
          



          Cela correspond-t-il à ce que tu recherches ?
          • Partager sur Facebook
          • Partager sur Twitter
            15 juin 2009 à 0:32:30

            OUIIIIIIIIIII! excellent, c'est ça! :D je suis super contente, merci, merci, merci!!! c'est ça merci :)
            • Partager sur Facebook
            • Partager sur Twitter
              5 juillet 2009 à 12:55:46

              Bonjour, je me permet de poster à la suite de ce message car j'aimerais savoir comment enregistrer seulement les images, par l'intermédiaire de leur "id", que l'ont a déplacé dans le second tableau.

              Par exemple :
              <img src="http://www.google.fr/intl/fr_fr/images/logo.gif" id="img1" />
              


              Comment pourrais-je avoir juste le "img1" quand je cliques sur "Save", si tenté que j'ai préalablement nommé mon image comme ça ?
              • Partager sur Facebook
              • Partager sur Twitter
                5 juillet 2009 à 13:23:08

                Hum... je ne suis pas sûr d'avoir tout compris...

                Tu peux récupérer les éléments <img> avec la méthode getElementsByTagName("img") qui renvoie un array d'éléments...

                A partir de là, tu peux donc récupérer les img contenues dans un élément, et sauvegarder leurs id...
                • Partager sur Facebook
                • Partager sur Twitter
                  5 juillet 2009 à 13:29:24

                  Disons que j'ai par exemple 4 images :

                  <img src="http://www.siteduzero.com/Templates/images/designs/2/homepage/icone_apprendre.png" id="img1" />
                  <img src="http://www.siteduzero.com/Templates/images/designs/2/homepage/icone_echanger.png" id="img2" />
                  <img src="http://www.siteduzero.com/Templates/images/designs/2/homepage/icone_informer.png" id="img3" />
                  <img src="http://www.siteduzero.com/uploads/fr/icones/defaut_mini.png" id="img4" />
                  


                  J'ai en id des ses images "img1", "img2", "img3", et "img4".

                  Si par exemple je met la 3éme image dans mon tableau de droite, comment faire que pour quand je clic sur "Save" il ne m'affiche que "img3", soit l'id de l'image que j'ai déplacé ?
                  • Partager sur Facebook
                  • Partager sur Twitter
                    5 juillet 2009 à 13:45:42

                    Attends attends, j'ai du mal à te suivre là.

                    Reprenons du début... quel code utilises-tu ? Celui que j'ai posté précédemment (le post vert) ?

                    Peux-tu me donner le code de ta page (avec JS et CSS inclus) ?

                    • Partager sur Facebook
                    • Partager sur Twitter
                      5 juillet 2009 à 14:01:10

                      J'utilise le code vert que tu as posté.

                      Voici mon code :

                      <div class="contenu">
                      	<!-- header -->
                      	<div class="header">
                      		Marchand :
                      	</div>
                      	
                      	<div class="cont">
                      


                      <style type="text/css">
                      
                      	#dhtmlgoodies_dragDropContainer{	/* Main container for this script */
                      		-moz-user-select:none;
                      	}
                      	#dhtmlgoodies_dragDropContainer ul{	/* General rules for all <ul> */
                      		margin-top:0px;
                      		margin-left:0px;
                      		margin-bottom:0px;
                      		padding:2px;
                      	}
                      	
                      	#dhtmlgoodies_dragDropContainer li,#dragContent li,li#indicateDestination{	/* Movable items, i.e. <LI> */
                      		list-style-type:none;
                      		height:30px;
                      		border:1px solid #000;
                      		padding:2px;
                      		margin-bottom:2px;
                      		cursor:move;
                      		font-size:0.9em;
                      	}
                      	
                      	li#indicateDestination{	/* Box indicating where content will be dropped - i.e. the one you use if you don't use arrow */
                      		border:1px dotted #600;	
                      	}
                      
                      	
                      	/* LEFT COLUMN CSS */
                      	div#dhtmlgoodies_listOfItems{	/* Left column "Available students" */
                      		
                      		float:left;
                      		padding-left:10px;
                      		padding-right:10px;
                      		
                      		/* CSS HACK */
                      		width: 180px;	/* IE 5.x */
                      		width/* */:/**/160px;	/* Other browsers */
                      		width: /**/160px;
                      				
                      	}
                      	#dhtmlgoodies_listOfItems ul{	/* Left(Sources) column <ul> */
                      		height:560px;	
                      
                      	}
                      		
                      	div#dhtmlgoodies_listOfItems div{
                      		border:1px solid #999;		
                      	}
                      	div#dhtmlgoodies_listOfItems div ul{	/* Left column <ul> */
                      		margin-left:10px;	/* Space at the left of list - the arrow will be positioned there */
                      	}
                      	#dhtmlgoodies_listOfItems div p{	/* Heading above left column */
                      		margin:0px;	
                      		font-weight:bold;
                      		padding-left:12px;
                      		background-color:#317082;	
                      		color:#FFF;
                      		margin-bottom:5px;
                      	}
                      	/* END LEFT COLUMN CSS */
                      	
                      	#dhtmlgoodies_dragDropContainer .mouseover{	/* Mouse over effect DIV box in right column */
                      		background-color:#E2EBED;
                      		border:1px solid #317082;
                      	}
                      	
                      	/* Start main container CSS */
                      	
                      	div#dhtmlgoodies_mainContainer{	/* Right column DIV */
                      		width:590px;
                      		float:left;	
                      	}
                      	#dhtmlgoodies_mainContainer div{	/* Parent <div> of small boxes */
                      		float:left;
                      		margin-right:10px;
                      		margin-bottom:10px;
                      		margin-top:0px;
                      		border:1px solid #999;
                      
                      		/* CSS HACK */
                      		width: 172px;	/* IE 5.x */
                      		width/* */:/**/170px;	/* Other browsers */
                      		width: /**/170px;
                      				
                      	}
                      	#dhtmlgoodies_mainContainer div ul{
                      		margin-left:10px;
                      	}
                      	
                      	#dhtmlgoodies_mainContainer div p{	/* Heading above small boxes */
                      		margin:0px;
                      		padding:0px;
                      		padding-left:12px;
                      		font-weight:bold;
                      		background-color:#317082;	
                      		color:#FFF;	
                      		margin-bottom:5px;
                      	}
                      	
                      	#dhtmlgoodies_mainContainer ul{	/* Small box in right column ,i.e <ul> */
                      		text-align:center;
                      		width:40px;
                      		height:80px;	
                      		border:0;	
                      		margin-bottom:0px;
                      		overflow:hidden;
                      		
                      	}
                      	#dhtmlgoodies_mainContainer table {
                      		border-collapse:collapse;
                      		float:left;
                      		margin-left:40px;
                      	}
                      	#dhtmlgoodies_mainContainer td {
                      		border:1px solid red;
                      	}
                      	
                      	#dragContent{	/* Drag container */
                      		position:absolute;
                      		text-align:center;
                      		width:40px;
                      		height:30px;
                      		display:none;
                      		margin:0px;
                      		padding:0px;
                      		z-index:2000;
                      	}
                      
                      	#dragDropIndicator{	/* DIV for the small arrow */
                      		position:absolute;
                      		width:7px;
                      		height:10px;
                      		display:none;
                      		z-index:1000;
                      		margin:0px;
                      		padding:0px;
                      	}
                      	
                      	div#dhtmlgoodies_listOfItems{
                      		display:none;
                      	}
                      	#dhtmlgoodies_dragDropContainer{
                      		border:0px;
                      		width:100%;
                      	}
                      	</style>
                      


                      <script type="text/javascript">
                      	/************************************************************************************************************
                      	(C) www.dhtmlgoodies.com, November 2005
                      	
                      	Update log:
                      	
                      	December 20th, 2005 : Version 1.1: Added support for rectangle indicating where object will be dropped
                      	January 11th, 2006: Support for cloning, i.e. "copy & paste" items instead of "cut & paste"
                      	January 18th, 2006: Allowing multiple instances to be dragged to same box(applies to "cloning mode")
                      	
                      	This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website.	
                      	
                      		Terms of use:
                      	You are free to use this script as long as the copyright message is kept intact. However, you may not
                      	redistribute, sell or repost it without our permission.
                      	
                      	Thank you!
                      	
                      	www.dhtmlgoodies.com
                      	Alf Magne Kalleland
                      	
                      	************************************************************************************************************/
                      		
                      	/* VARIABLES YOU COULD MODIFY */
                      	var boxSizeArray = [1,1,1,1,1,1,1,1];	// Array indicating how many items there is rooom for in the right column ULs
                      	
                      	var arrow_offsetX = -5;	// Offset X - position of small arrow
                      	var arrow_offsetY = 0;	// Offset Y - position of small arrow
                      	
                      	var arrow_offsetX_firefox = -6;	// Firefox - offset X small arrow
                      	var arrow_offsetY_firefox = -13; // Firefox - offset Y small arrow
                      	
                      	var verticalSpaceBetweenListItems = 3;	// Pixels space between one <li> and next	
                      											// Same value or higher as margin bottom in CSS for #dhtmlgoodies_dragDropContainer ul li,#dragContent li
                      	
                      											
                      	var indicateDestionationByUseOfArrow = false;	// Display arrow to indicate where object will be dropped(false = use rectangle)
                      
                      	var cloneSourceItems = false;	// Items picked from main container will be cloned(i.e. "copy" instead of "cut").	
                      	var cloneAllowDuplicates = true;	// Allow multiple instances of an item inside a small box(example: drag Student 1 to team A twice
                      	
                      	/* END VARIABLES YOU COULD MODIFY */
                      	
                      	var dragDropTopContainer = false;
                      	var dragTimer = -1;
                      	var dragContentObj = false;
                      	var contentToBeDragged = false;	// Reference to dragged <li>
                      	var contentToBeDragged_src = false;	// Reference to parent of <li> before drag started
                      	var contentToBeDragged_next = false; 	// Reference to next sibling of <li> to be dragged
                      	var destinationObj = false;	// Reference to <UL> or <LI> where element is dropped.
                      	var dragDropIndicator = false;	// Reference to small arrow indicating where items will be dropped
                      	var ulPositionArray = new Array();
                      	var mouseoverObj = false;	// Reference to highlighted DIV
                      	
                      	var MSIE = navigator.userAgent.indexOf('MSIE')>=0?true:false;
                      	var navigatorVersion = navigator.appVersion.replace(/.*?MSIE (\d\.\d).*/g,'$1')/1;
                      
                      	
                      	var indicateDestinationBox = false;
                      	function getTopPos(inputObj)
                      	{		
                      	  var returnValue = inputObj.offsetTop;
                      	  while((inputObj = inputObj.offsetParent) != null){
                      	  	if(inputObj.tagName!='HTML')returnValue += inputObj.offsetTop;
                      	  }
                      	  return returnValue;
                      	}
                      	
                      	function getLeftPos(inputObj)
                      	{
                      	  var returnValue = inputObj.offsetLeft;
                      	  while((inputObj = inputObj.offsetParent) != null){
                      	  	if(inputObj.tagName!='HTML')returnValue += inputObj.offsetLeft;
                      	  }
                      	  return returnValue;
                      	}
                      		
                      	function cancelEvent()
                      	{
                      		return false;
                      	}
                      	function initDrag(e)	// Mouse button is pressed down on a LI
                      	{
                      		if(document.all)e = event;
                      		var st = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
                      		var sl = Math.max(document.body.scrollLeft,document.documentElement.scrollLeft);
                      		
                      		dragTimer = 0;
                      		dragContentObj.style.left = e.clientX + sl + 'px';
                      		dragContentObj.style.top = e.clientY + st + 'px';
                      		contentToBeDragged = this;
                      		contentToBeDragged_src = this.parentNode;
                      		contentToBeDragged_next = false;
                      		if(this.nextSibling){
                      			contentToBeDragged_next = this.nextSibling;
                      			if(!this.tagName && contentToBeDragged_next.nextSibling)contentToBeDragged_next = contentToBeDragged_next.nextSibling;
                      		}
                      		timerDrag();
                      		return false;
                      	}
                      	
                      	function timerDrag()
                      	{
                      		if(dragTimer>=0 && dragTimer<10){
                      			dragTimer++;
                      			setTimeout('timerDrag()',10);
                      			return;
                      		}
                      		if(dragTimer==10){
                      			
                      			if(cloneSourceItems && contentToBeDragged.parentNode.id=='allItems'){
                      				newItem = contentToBeDragged.cloneNode(true);
                      				newItem.onmousedown = contentToBeDragged.onmousedown;
                      				contentToBeDragged = newItem;
                      			}
                      			dragContentObj.style.display='block';
                      			dragContentObj.appendChild(contentToBeDragged);
                      		}
                      	}
                      	
                      	function moveDragContent(e)
                      	{
                      		if(dragTimer<10){
                      			if(contentToBeDragged){
                      				if(contentToBeDragged_next){
                      					contentToBeDragged_src.insertBefore(contentToBeDragged,contentToBeDragged_next);
                      				}else{
                      					contentToBeDragged_src.appendChild(contentToBeDragged);
                      				}	
                      			}
                      			return;
                      		}
                      		if(document.all)e = event;
                      		var st = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
                      		var sl = Math.max(document.body.scrollLeft,document.documentElement.scrollLeft);
                      		
                      		
                      		dragContentObj.style.left = e.clientX + sl + 'px';
                      		dragContentObj.style.top = e.clientY + st + 'px';
                      		
                      		if(mouseoverObj)mouseoverObj.className='';
                      		destinationObj = false;
                      		dragDropIndicator.style.display='none';
                      		if(indicateDestinationBox)indicateDestinationBox.style.display='none';
                      		var x = e.clientX + sl;
                      		var y = e.clientY + st;
                      		var width = dragContentObj.offsetWidth;
                      		var height = dragContentObj.offsetHeight;
                      		
                      		var tmpOffsetX = arrow_offsetX;
                      		var tmpOffsetY = arrow_offsetY;
                      		if(!document.all){
                      			tmpOffsetX = arrow_offsetX_firefox;
                      			tmpOffsetY = arrow_offsetY_firefox;
                      		}
                      
                      		for(var no=0;no<ulPositionArray.length;no++){
                      			var ul_leftPos = ulPositionArray[no]['left'];	
                      			var ul_topPos = ulPositionArray[no]['top'];	
                      			var ul_height = ulPositionArray[no]['height'];
                      			var ul_width = ulPositionArray[no]['width'];
                      			
                      			if((x+width) > ul_leftPos && x<(ul_leftPos + ul_width) && (y+height)> ul_topPos && y<(ul_topPos + ul_height)){
                      				var noExisting = ulPositionArray[no]['obj'].getElementsByTagName('LI').length;
                      				if(indicateDestinationBox && indicateDestinationBox.parentNode==ulPositionArray[no]['obj'])noExisting--;
                      				if(noExisting<boxSizeArray[no-1] || no==0){
                      					dragDropIndicator.style.left = ul_leftPos + tmpOffsetX + 'px';
                      					var subLi = ulPositionArray[no]['obj'].getElementsByTagName('LI');
                      					
                      					var clonedItemAllreadyAdded = false;
                      					if(cloneSourceItems && !cloneAllowDuplicates){
                      						for(var liIndex=0;liIndex<subLi.length;liIndex++){
                      							if(contentToBeDragged.id == subLi[liIndex].id)clonedItemAllreadyAdded = true;
                      						}
                      						if(clonedItemAllreadyAdded)continue;
                      					}
                      					
                      					for(var liIndex=0;liIndex<subLi.length;liIndex++){
                      						var tmpTop = getTopPos(subLi[liIndex]);
                      						if(!indicateDestionationByUseOfArrow){
                      							if(y<tmpTop){
                      								destinationObj = subLi[liIndex];
                      								indicateDestinationBox.style.display='block';
                      								subLi[liIndex].parentNode.insertBefore(indicateDestinationBox,subLi[liIndex]);
                      								break;
                      							}
                      						}else{							
                      							if(y<tmpTop){
                      								destinationObj = subLi[liIndex];
                      								dragDropIndicator.style.top = tmpTop + tmpOffsetY - Math.round(dragDropIndicator.clientHeight/2) + 'px';
                      								dragDropIndicator.style.display='block';
                      								break;
                      							}	
                      						}					
                      					}
                      					
                      					if(!indicateDestionationByUseOfArrow){
                      						if(indicateDestinationBox.style.display=='none'){
                      							indicateDestinationBox.style.display='block';
                      							ulPositionArray[no]['obj'].appendChild(indicateDestinationBox);
                      						}
                      						
                      					}else{
                      						if(subLi.length>0 && dragDropIndicator.style.display=='none'){
                      							dragDropIndicator.style.top = getTopPos(subLi[subLi.length-1]) + subLi[subLi.length-1].offsetHeight + tmpOffsetY + 'px';
                      							dragDropIndicator.style.display='block';
                      						}
                      						if(subLi.length==0){
                      							dragDropIndicator.style.top = ul_topPos + arrow_offsetY + 'px'
                      							dragDropIndicator.style.display='block';
                      						}
                      					}
                      					
                      					if(!destinationObj)destinationObj = ulPositionArray[no]['obj'];
                      					mouseoverObj = ulPositionArray[no]['obj'].parentNode;
                      					mouseoverObj.className='mouseover';
                      					return;
                      				}
                      			}
                      		}
                      	}
                      	
                      	/* End dragging 
                      	Put <LI> into a destination or back to where it came from.
                      	*/	
                      	function dragDropEnd(e)
                      	{
                      		if(dragTimer==-1)return;
                      		if(dragTimer<10){
                      			dragTimer = -1;
                      			return;
                      		}
                      		dragTimer = -1;
                      		if(document.all)e = event;	
                      		
                      		
                      		if(cloneSourceItems && (!destinationObj || (destinationObj && (destinationObj.id=='allItems' || destinationObj.parentNode.id=='allItems')))){
                      			contentToBeDragged.parentNode.removeChild(contentToBeDragged);
                      		}else{	
                      			
                      
                      			if(destinationObj){
                      				if(destinationObj.tagName=='UL'){
                      					destinationObj.appendChild(contentToBeDragged);
                      				}else{
                      					destinationObj.parentNode.insertBefore(contentToBeDragged,destinationObj);
                      				}
                      				mouseoverObj.className='';
                      				destinationObj = false;
                      				dragDropIndicator.style.display='none';
                      				if(indicateDestinationBox){
                      					indicateDestinationBox.style.display='none';
                      					document.body.appendChild(indicateDestinationBox);
                      				}
                      				contentToBeDragged = false;
                      				return;
                      			}		
                      			if(contentToBeDragged_next){
                      				contentToBeDragged_src.insertBefore(contentToBeDragged,contentToBeDragged_next);
                      			}else{
                      				contentToBeDragged_src.appendChild(contentToBeDragged);
                      			}
                      		}
                      		contentToBeDragged = false;
                      		dragDropIndicator.style.display='none';
                      		if(indicateDestinationBox){
                      			indicateDestinationBox.style.display='none';
                      			document.body.appendChild(indicateDestinationBox);
                      			
                      		}
                      		mouseoverObj = false;
                      		
                      	}
                      	
                      	/* 
                      	Preparing data to be saved 
                      	*/
                      	function saveDragDropNodes()
                      	{
                      		var saveString = "";
                      		var uls = dragDropTopContainer.getElementsByTagName('UL');
                      		for(var no=0;no<uls.length;no++){	// LOoping through all <ul>
                      			var lis = uls[no].getElementsByTagName('LI');
                      			for(var no2=0;no2<lis.length;no2++){
                      				saveString = saveString + uls[no].id + lis[no2].id;
                      			}	
                      		}
                      		
                      		if(saveString == "") saveString = '0';
                      		
                      		document.getElementById('saveContent').innerHTML = '<h1>bdd :</h1> ' + saveString.replace(/;/g,';<br />');
                      		
                      	}
                      	
                      	function initDragDropScript()
                      	{
                      		dragContentObj = document.getElementById('dragContent');
                      		dragDropIndicator = document.getElementById('dragDropIndicator');
                      		dragDropTopContainer = document.getElementById('dhtmlgoodies_dragDropContainer');
                      		document.documentElement.onselectstart = cancelEvent;;
                      		var listItems = dragDropTopContainer.getElementsByTagName('LI');	// Get array containing all <LI>
                      		var itemHeight = false;
                      		for(var no=0;no<listItems.length;no++){
                      			listItems[no].onmousedown = initDrag;
                      			listItems[no].onselectstart = cancelEvent;
                      			if(!itemHeight)itemHeight = listItems[no].offsetHeight;
                      			if(MSIE && navigatorVersion/1<6){
                      				listItems[no].style.cursor='hand';
                      			}			
                      		}
                      		
                      		var mainContainer = document.getElementById('dhtmlgoodies_mainContainer');
                      		var uls = mainContainer.getElementsByTagName('UL');
                      		itemHeight = itemHeight + verticalSpaceBetweenListItems;
                      		for(var no=0;no<uls.length;no++){
                      			uls[no].style.height = itemHeight * boxSizeArray[no]  + 'px';
                      		}
                      		
                      		/*var leftContainer = document.getElementById('dhtmlgoodies_listOfItems');
                      		var itemBox = leftContainer.getElementsByTagName('UL')[0];*/
                      		
                      		document.documentElement.onmousemove = moveDragContent;	// Mouse move event - moving draggable div
                      		document.documentElement.onmouseup = dragDropEnd;	// Mouse move event - moving draggable div
                      		
                      		var ulArray = dragDropTopContainer.getElementsByTagName('UL');
                      		for(var no=0;no<ulArray.length;no++){
                      			ulPositionArray[no] = new Array();
                      			ulPositionArray[no]['left'] = getLeftPos(ulArray[no]);	
                      			ulPositionArray[no]['top'] = getTopPos(ulArray[no]);	
                      			ulPositionArray[no]['width'] = ulArray[no].offsetWidth;
                      			ulPositionArray[no]['height'] = ulArray[no].clientHeight;
                      			ulPositionArray[no]['obj'] = ulArray[no];
                      		}
                      		
                      		if(!indicateDestionationByUseOfArrow){
                      			indicateDestinationBox = document.createElement('LI');
                      			indicateDestinationBox.id = 'indicateDestination';
                      			indicateDestinationBox.style.display='none';
                      			document.body.appendChild(indicateDestinationBox);
                      
                      			
                      		}
                      	}
                      	
                      	window.onload = initDragDropScript;
                      	</script>
                      


                      <div id="dhtmlgoodies_dragDropContainer">
                        <div id="dhtmlgoodies_mainContainer">
                          <table id="tab6">
                            <tr>
                              <td>
                                <ul><li><img src="http://www.siteduzero.com/Templates/images/designs/2/homepage/icone_apprendre.png" id="img1" /></li></ul>
                              </td>
                              <td>
                                <ul><li><img src="http://www.siteduzero.com/Templates/images/designs/2/homepage/icone_echanger.png" id="img2" /></li></ul>
                              </td>
                              <td>
                                <ul><li><img src="http://www.siteduzero.com/Templates/images/designs/2/homepage/icone_informer.png" id="img3" /></li></ul>
                              </td>
                            </tr>
                            <tr>
                              <td>
                                <ul><li><img src="http://www.siteduzero.com/uploads/fr/icones/defaut_mini.png" id="img4" /></li></ul>
                              </td>
                              <td>
                                <ul></ul>
                              </td>
                              <td>
                                <ul></ul>
                              </td>
                            </tr>
                          </table>
                          <table>
                            <tr>
                              <td>
                                <ul id="porter"></ul>
                              </td>
                            </tr>
                          </table>
                        </div>
                      </div>
                      <div id="footer">
                      	<form method="post"><input type="button" onClick="saveDragDropNodes()" value="Save"></form>
                      </div>
                      <ul id="dragContent"></ul>
                      <div id="dragDropIndicator"><img src="" /></div>
                      <div id="saveContent"></div>
                      	</div>
                      </div>
                      


                      Le truc c'est que je souhaiterais récupérer le nom (name) ou l'id de mon image que je déplace, dans le but de l'enregistrer plus tard en php, dans une variable.

                      D'avance merci, cordialement, Gada
                      • Partager sur Facebook
                      • Partager sur Twitter
                        5 juillet 2009 à 17:23:32

                        Par exemple en remplaçant la fonction saveDragDropNodes() par celle-ci ?

                        function saveDragDropNodes()
                        	{
                        		/*var saveString = "";
                        		var uls = dragDropTopContainer.getElementsByTagName('UL');
                        		for(var no=0;no<uls.length;no++){	// LOoping through all <ul>
                        			var lis = uls[no].getElementsByTagName('LI');
                        			for(var no2=0;no2<lis.length;no2++){
                        				saveString = saveString + uls[no].id + lis[no2].id;
                        			}	
                        		}
                        		
                        		if(saveString == "") saveString = '0';*/
                        		
                        		//document.getElementById('saveContent').innerHTML = '<h1>bdd :</h1> ' + saveString.replace(/;/g,';<br />');
                                        document.getElementById("saveContent").innerHTML = document.getElementById("porter").getElementsByTagName("img")[0].id;
                        		
                        	}
                        
                        • Partager sur Facebook
                        • Partager sur Twitter
                          5 juillet 2009 à 17:26:39

                          Impeccable !!

                          Merci infiniment Golmote, merci beaucoup, tu me retire une énorme épine du pied !

                          Bonne journée :D
                          • Partager sur Facebook
                          • Partager sur Twitter
                            5 juillet 2009 à 17:31:03

                            De rien et bonne journée à toi aussi.

                            (A l'avenir, plutôt que de reprendre de vieux topics, crées-en un nouveau, en faisant un lien vers le topic auquel ton problème se rapporte ;) )
                            • Partager sur Facebook
                            • Partager sur Twitter
                              5 juillet 2009 à 18:20:31

                              Arff, encore un petit problème. Là j'ai bien mes noms d'id d'images qui apparaissent, mais quant je les remets dans le tableau de gauche, il m'affiche toujours le dernier id d'image dans <div id="saveContent"></div>. Le but étant d'enregistrer le nom de ma variable en php (là aussi, encore un autre problème).

                              Donc le truc serait de voir : si je met une image dans le tableau de droite, il me met son id, mais si je l'enlève et la remet dans le tableau de gauche, il faudrait qu'il s'affiche un "0".

                              Voici mon code pour la fonction enregistrer :

                              function saveDragDropNodes()
                              	{
                                      var saveString = document.getElementById("saveContent").innerHTML;
                              		if(saveString != ""){
                              			document.getElementById("saveContent").innerHTML = document.getElementById("porter").getElementsByTagName("img")[0].id;
                              		}
                              		else{
                              			document.getElementById("saveContent").innerHTML = '0';
                              		}
                              		
                              	}
                              


                              Le soucis étant que ça ne marche hélas pas.
                              • Partager sur Facebook
                              • Partager sur Twitter
                                5 juillet 2009 à 18:43:54

                                Essaie en changeant ta condition. Un truc genre...

                                if(!saveString || saveString=="0") {
                                
                                • Partager sur Facebook
                                • Partager sur Twitter
                                  5 juillet 2009 à 20:53:27

                                  au top !

                                  merci beaucoup :)
                                  • Partager sur Facebook
                                  • Partager sur Twitter

                                  galère pour un drag and drop!!

                                  × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
                                  × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
                                  • Editeur
                                  • Markdown