> >> > I know how to display random jokes or sayings. But only if I reload
> >> > the page does the script select a new saying. How can I click on
> >> > the saying and have it load a new one in its place.
> >> >
> >>
> >> <script>
> >> j=new Array
> >> j[0]="haha"
> >> j[1]="next joke"
> >> j[2]="again"
> >> //....
> >> j[20]="last joke"
> >> </script>
> >>
> >> <div onclick="this.innerHTML=j[Math.floor(Math.random()*21)]">
> >> Click here for jokes
> >> </div>
> >
> >
> > This did not quite work. This is just about what I wanted. I keep
> > geting a message that says undefined. I think that the part after
> > innerHTML= has to be in the script too.
> >
>
> It works all right, tested on IE6, but you have to fill in all 20 texts,
> otherwise you get that "undefined"
>
> Or you could do Math.random()*3
Or better, use Math.floor(Math.random() * j.length). That way, you don't have to
edit the script when the number of jokes changes. And better still, use the
literal array notation. That way, you don't have to number the jokes.
j = [
"haha",
"again",
"last joke"];
http://www.JSON.org