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
   | function addrow(nform,nom,nb,ids,values,check){
	//Reconstruire les tableaux pour la liste de valeurs
	var key=ids.split("|",-1);
	var val=values.split("|",-1);	
 
	var form=document.getElementById(nform);
 
	//Si la dernière case est cliquée
	if((document.getElementById(nom+3)==null&&check.checked)||(document.getElementById(nom+(parseInt(nb)+3))==null)){
		//Repérer le node suivant pour les insertions d'éléments
		var next=document.getElementById(nom+(parseInt(nb)+2)).nextSibling;
 
		//Sauter une ligne
		var br=document.createElement("br");
		form.insertBefore(br,next);
 
		//Créer la nvlle checkbox
		var nouvoc=document.createElement("input");
		nouvoc.setAttribute("type","checkbox");
		nouvoc.setAttribute("name",nom+"check[]");
		nouvoc.setAttribute("id",nom+(parseInt(nb)+3));
		nouvoc.setAttribute("onChange","addrow('"+ nform +"','"+ nom +"','"+ (parseInt(nb)+3) +"','"+ ids +"','"+ values +"')");
		form.insertBefore(nouvoc,next);
 
		//Créer le nouveau select
		var nouvol=document.createElement("select");
		nouvol.setAttribute("id",nom+(parseInt(nb)+4));
		nouvol.setAttribute("disabled","disabled");
		nouvol.setAttribute("name",nom+"[]");
		form.insertBefore(nouvol,next);
 
		//Remplir les options du nouveau select
		for(var i=0;i<key.length;i++){
			opt=new Option(val[i],key[i],false,false);
			nouvol.options[i]=opt;
		}
 
		//Créer le nouveau champ de texte
		var nouvot=document.createElement("input");
		nouvot.setAttribute("id",nom+(parseInt(nb)+5));
		nouvot.setAttribute("disabled","disabled");
		nouvot.setAttribute("name","distance"+nom+"[]");
		nouvot.setAttribute("type","text");
		form.insertBefore(nouvot,next);
	}
	//Griser/Dégriser
	if(document.getElementById(nom+(parseInt(nb)+1)).disabled){ document.getElementById(nom+(parseInt(nb)+1)).disabled=false; document.getElementById(nom+(parseInt(nb)+2)).disabled=false; }
	else{ document.getElementById(nom+(parseInt(nb)+1)).disabled=true; document.getElementById(nom+(parseInt(nb)+2)).disabled=true; }
} | 
Partager