| darkoli |
voila, dans la page html qui suit il est possible de transferer des elements de la liste 1 à la liste 2 et inversement. Si tu as des problemes de comprehension n'hesite pas.
j'ai testé sur ie5 ca marche, pour ie4 à voir.
Code :
- <html>
- <head>
- <title>transfert entre listes</title>
- </head>
- <body>
- <script language="javascript">
- var ne=0;
- var te=new Array();
- function ee(i,t,l) {
- this.id=i;
- this.texte=t;
- this.liste=l; // indique la liste ou se trouve l'element : 0 ou 1
- }
- function ae(i,t,l) {
- te[ne]=new ee(i,t,l);
- ne++;
- }
- function il(l) {
- var s="";
- var n=0;
- for (var i=0;i<ne;i++) {
- if (te[i].liste==l) {
- s=s+"<option value=\""+te[i].id+"\">"+te[i].texte+"</option>";
- n++;
- }
- }
- for (var i=n;i<ne;i++) {
- s=s+"<option value=\"x\"></option>";
- }
- return(s);
- }
- function l12() {
- var n1=0;
- var n2=0;
- for (var i=0;i<ne;i++) {
- if (te[i].liste==1) {
- document.all.l1.options[n1].value=te[i].id;
- document.all.l1.options[n1].text=te[i].texte;
- n1++;
- }
- else {
- document.all.l2.options[n2].value=te[i].id;
- document.all.l2.options[n2].text=te[i].texte;
- n2++;
- }
- }
- for (var i=n1;i<ne;i++) {
- document.all.l1.options[i].value="x";
- document.all.l1.options[i].text="";
- }
- for (var i=n2;i<ne;i++) {
- document.all.l2.options[i].value="x";
- document.all.l2.options[i].text="";
- }
- }
- function e1() {
- if (document.all.l2.selectedIndex<0) return;
- var n=document.all.l2.options[document.all.l2.selectedIndex].value;
- for (var i=0;i<ne;i++) {
- if (te[i].id==n) {
- te[i].liste=1;
- }
- }
- l12();
- }
- function e2() {
- if (document.all.l1.selectedIndex<0) return;
- var n=document.all.l1.options[document.all.l1.selectedIndex].value;
- for (var i=0;i<ne;i++) {
- if (te[i].id==n) {
- te[i].liste=2;
- }
- }
- l12();
- }
- function et1() {
- for (var i=0;i<ne;i++) te[i].liste=1;
- l12();
- }
- function et2() {
- for (var i=0;i<ne;i++) te[i].liste=2;
- l12();
- }
- ae( 0,"Lundi",2);
- ae( 1,"Mardi",2);
- ae( 2,"Mercredi",2);
- ae( 3,"Jeudi",2);
- ae( 4,"Vendredi",2);
- ae( 5,"Samedi",2);
- ae( 6,"Dimanche",2);
- ae( 7,"janvier",1);
- ae( 8,"février",1);
- ae( 9,"mars",1);
- ae(10,"avril",1);
- ae(11,"mai",1);
- ae(12,"juin",1);
- ae(13,"juillet",1);
- ae(14,"aout",1);
- ae(15,"septembre",1);
- ae(16,"octobre",1);
- ae(17,"novembre",1);
- ae(18,"decembre",1);
- </script>
- <table>
- <tr><td>
- <select name="l1" multiple size="16"><script language="javascript">document.write(il(1))</script></select>
- </td>
- <td>
- <table>
- <tr><td><input type="button" value=" > " onClick="e2()"></td></tr>
- <tr><td><input type="button" value=" < " onClick="e1()"></td></tr>
- <tr><td><input type="button" value="<<"onClick="et1()"></td></tr>
- <tr><td><input type="button" value=">>"onClick="et2()"></td></tr>
- </table>
- </td>
- <td>
- <select name="l2" multiple size="16"><script language="javascript">document.write(il(2))</script></select>
- </td></tr>
- </table>
- </body>
- </html>
|
|