Question : 4 functions and call one randomly on click

Hey,
I'm trying to sort out a script which will goto a random function on click but it's not going as planned.
Please advise,
Thanks in advance,
Ian
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:
<script type="text/javascript">
function getRandom(min, max)
{		
var randomNum = Math.random() * (max-min); 


return(Math.round(randomNum) + min); 
}
function change0(){
document.getElementById("text").value="Change0"
}
function change1(){
document.getElementById("text").value="Change1"
}
function change2(){
document.getElementById("text").value="Change2"
}
function change3(){
document.getElementById("text").value="Change3"
}

function choose(){
var ry = getRandom(0, 3)

document.write('change'+[ry]+'()')
}
</script>  

<div id="text1"><div id="text"></div></div>
<input type="button" onclick="choose()">

Answer : 4 functions and call one randomly on click

You need to use innerHTML to set "text" in div.

Check this :

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:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
	var functions = [change0,change1,change2,change3];
	
	function getRandom(min, max)
	{
		var randomNum = Math.random() * (max-min);
		return(Math.round(randomNum) + min); 
	}
	function change0() {
		document.getElementById("text").innerHTML="Change0";
	}
	function change1() {
		document.getElementById("text").innerHTML="Change1";
	}
	function change2() {
		document.getElementById("text").innerHTML="Change2";
	}
	function change3() {
		document.getElementById("text").innerHTML="Change3";
	}
	
	function choose() {
		var ry = getRandom(0, 3)
		functions[ry]();
	}
</script>
</head>
<body>
<div id="text1"><div id="text"></div></div>
<input type="button" onclick="choose()" value="click me" />
</body>
</html>
Random Solutions  
 
programming4us programming4us