Hello,
J'ai 2 div (div1 et div2) contenant du texte que je concatène et affiche dans div3 lors d'un clic sur un boutton.
J'aimerais que ce soit récursif à savoir à chaque clic:
div3=div3+div1+div2
J'ai le code ci-dessous
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
<?php
// Generate a random character string
function rand_str($length = 32, $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890')
{
    // Length of character list
    $chars_length = (strlen($chars) - 1);
 
    // Start our string
    $string = $chars{rand(0, $chars_length)};
 
    // Generate random string
    for ($i = 1; $i < $length; $i = strlen($string))
    {
        // Grab a random character from our list
        $r = $chars{rand(0, $chars_length)};
 
        // Make sure the same two characters don't appear next to each other
        if ($r != $string{$i - 1}) $string .=  $r;
    }
 
    // Return the string
    return $string;
}
 
?>
<html>
<head>
<script type="text/javascript">
	function defile(){
		var x;
		var k=0;
		var d = new Date();
		var j = d.getDate();
		var m = d.getMonth()+1;
		var y = 00+d.getYear();
		var h = d.getHours();
		var mn = d.getMinutes();
		var s = d.getSeconds();
		var date = j+"-"+m+"-"+y+" "+h+":"+mn+":"+s;
 
		var cont1=document.getElementById("div1");
		var cont2=document.getElementById("div2");
		var cont3=document.getElementById("div3");
		cont3.innerHTML = cont3.innerHTML+"<br>"+date+" --"+cont2.innerHTML + " - " + cont1.innerHTML+"<br>";
		/*cont1.innerHTML="";
		cont2.innerHTML="";*/
	}
</script>
</head>
<body >
<div id="div1">div1: <?php echo rand_str();?></div>
<div id="div2">div2: <?php echo rand_str();?></div>
<br><br><br><div id="div3"></div>
<input type="button" id="ok" value="ok" onclick="defile();return false;">
</body>
</html>
Sauf qu'à chaque clic, j'ai l'impression que le contenu précédent de div3 n'est pas pris en compte.

Ou est l'erreur svp?