Bonjour
j'ai une page fille qui est une PopUp avec une liste de radio buttons.
Quand je clique sur TRANSFERT dans ma popup, le radio button selectionne dans ma Pop Up me permet de cree une nouvelle option dans un select multiple de la page mere.
Page Fille:
Page Mere:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 <script type="text/javascript"> function TransfertFilleMere(){ for (var i=0; i < document.paramform.ap.length; i++){ if (document.paramform.ap[i].checked) { var rad_val = document.paramform.ap[i].value; var rad_text = document.getElementById("span_" + rad_val).innerText; } } var elmtWinParent=window.opener.document.getElementById("tunp") y=window.opener.document.createElement('option'); y.value=rad_val; y.text=rad_text; y.selected="selected"; try { elmtWinParent.add(y,null); // standards compliant } catch(ex){ elmtWinParent.add(y); // IE only } } </script> <form name="paramform"> <input type="radio" name="ap" value="1" /><span id = span_1>Param1</span><br /> <input type="radio" name="ap" value="2" /><span id = span_2>Param2</span><br /> <input type="radio" name="ap" value="3" /><span id = span_3>Param3</span><br /> <input type="radio" name="ap" value="4" /><span id = span_4>Param4</span> <br /> <input type="radio" name="ap" value="5" /><span id = span_5>Param5</span> <br /> <input type="radio" name="ap" value="6" /><span id = span_6>Param6</span><br /> </select> <input type="button" value="Transfert" onclick="TransfertFilleMere()"> </form>
Dans la page Mere, je voudrais reafficher les select multiples qui ont ete ajoutees par l'utilisateur.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
50
51
52
53
54
55
56
57
58
59
60 <head> <script> var mywindow = null; function ohh(){ if(mywindow != null && mywindow.closed == false) { alert("The window is already open"); } else { mywindow = window.open("fille_avant.php","PopUp", "width=500,height=400,left=" + ((screen.width - 500)/2) + ",top=" + ((screen.height - 400)/2) + "location=yes,status=yes,toolbar=yes,scrollbars=yes resizable=yes"); } } function gettxt(myselect){ var x=document.getElementById("tunp"); for (i=0;i<x.length;i++){ var val=x.options[i].value; if (val==myselect){ txt =x.options[i].innerText; return txt; } } } </script> </head> <body> <?php print_r($_POST)?> <?php if (isset($_POST['submit'])){ $table=$_POST; print_r($table['variables']); echo '<form id="form1" method="post">'; echo '<select name="variables[]" id="tunp" multiple="multiple">'; foreach ($table['variables'] as $k => $i){ echo '<option value="' . $i . '" selected="selected"><script>gettxt(' . $i . ')</script></option>'; } echo '</select><br/>'; echo '<input type="button" name="lancer" value="Ouvre" onclick="ohh()">'; echo '<br /><br /><br />'; echo '<input type="submit" name="submit" value="Enter">'; echo '<br /><br /><br />'; echo '</form>'; } else { ?> <form id="form1" method="post"> <select name="variables[]" id="tunp" multiple="multiple"> </select><br/> <input type="button" name="lancer" value="Ouvre" onclick="ohh()"> <br /><br /><br /> <input type="submit" name="submit" value="Enter"> <br /><br /><br /> </form> <?php } ?> </body>
Et pour ce faire je recupere le TEXT d'une option de mon select multiple grace a la function gettxt(myselect) et j'appelle cette fonction JS comme cela:Mais voila quand j'ajoute des options dans ma page mere et que je soumets mon formulaire, je ne vois pas le texte de lóption.foreach ($table['variables'] as $k => $i){
echo '<option value="' . $i . '" selected="selected"><script>gettxt(' . $i . ')</script></option>';
}
Voila le code source genere quand je fais VIEW SOURCE:
Je ne sais pas pourquoi gettxt(1), gettxt(2) etc ne renvoient aucun resultat.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 <head> <script> var mywindow = null; function ohh(){ if(mywindow != null && mywindow.closed == false) { alert("The window is already open"); } else { mywindow = window.open("fille_avant.php","PopUp", "width=500,height=400,left=" + ((screen.width - 500)/2) + ",top=" + ((screen.height - 400)/2) + "location=yes,status=yes,toolbar=yes,scrollbars=yes resizable=yes"); } } function gettxt(myselect){ var x=document.getElementById("tunp"); for (i=0;i<x.length;i++){ var val=x.options[i].value; if (val==myselect){ txt =x.options[i].innerText; return txt; } } } </script> </head> <body> Array ( [variables] => Array ( [0] => 1 [1] => 2 [2] => 4 [3] => 5 ) [submit] => Enter ) <form id="form1" method="post"><select name="variables[]" id="tunp" multiple="multiple"><option value="1" selected="selected"><script>gettxt(1)</script></option><option value="2" selected="selected"><script>gettxt(2)</script></option><option value="4" selected="selected"><script>gettxt(4)</script></option><option value="5" selected="selected"><script>gettxt(5)</script></option></select><br/><input type="button" name="lancer" value="Ouvre" onclick="ohh()"><br /><br /><br /><input type="submit" name="submit" value="Enter"><br /><br /><br /></form> </body>
Merci d'avance pour votre aide.
Billy
Partager