![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
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. |
#3
| |||
| |||
|
|
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. |
#4
| |||
| |||
|
|
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. |
#5
| |||
| |||
|
|
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. Javascript is CLIENT SIDE |
#6
| |||
| |||
|
|
Michael wrote on 22 sep 2003 in comp.lang.javascript: 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 |
#7
| |||
| |||
|
|
"Evertjan." <exjxw.hannivoort (AT) interxnl (DOT) net> wrote in message news:<Xns93FEECF282858eejj99 (AT) 194 (DOT) 109.133.29>... Michael wrote on 22 sep 2003 in comp.lang.javascript: 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. |
#8
| |||
| |||
|
|
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 |
#9
| |||
| |||
|
|
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"]; Or realize that there are no new jokes. |
#10
| |||
| |||
|
|
j=new Array j[0]="haha" j[1]="next joke" j[2]="again" //.... j[20]="last joke" /script Or you could do Math.random()*3 Or better, use Math.floor(Math.random() * j.length). That way, you don't have to |
![]() |
| Thread Tools | |
| Display Modes | |
| |