HighDots Forums  

How can I click on a joke and have a new joke appear?

Javascript JavaScript language (comp.lang.javascript)


Discuss How can I click on a joke and have a new joke appear? in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #11  
Old   
Evertjan.
 
Posts: n/a

Default Re: How can I click on a joke and have a new joke appear? Part 2 - 09-26-2003 , 04:01 AM






Mike Painter wrote on 26 sep 2003 in comp.lang.javascript:
Quote:
j = [
"haha",
"again",
"last joke"];

Or realize that there are no new jokes.
That is a good one !

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)


Reply With Quote
  #12  
Old   
Lasse Reichstein Nielsen
 
Posts: n/a

Default Re: How can I click on a joke and have a new joke appear? Part 2 - 09-26-2003 , 05:52 AM






"Mike Painter" <mdotpainter (AT) att (DOT) net> writes:

Quote:
"Douglas Crockford" <nospam (AT) laserlink (DOT) net> wrote in message
news:bkvlq1$jas$1 (AT) sun-news (DOT) laserlink.net...
snip
That way, you don't have to number the jokes.

Or realize that there are no new jokes.
#751 ?

/L
--
Lasse Reichstein Nielsen - lrn (AT) hotpop (DOT) com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'


Reply With Quote
  #13  
Old   
Douglas Crockford
 
Posts: n/a

Default Re: How can I click on a joke and have a new joke appear? Part 2 - 09-26-2003 , 07:27 AM



Quote:
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


Not in the case under investigation, where there is a gap in the array !
The point was that if the literal object notation is used, there won't be a gap.

var j = ["haha", "next joke", "again", "last joke"];

Smaller, faster, easier to edit, no gaps.

http://www.JSON.org



Reply With Quote
  #14  
Old   
Michael
 
Posts: n/a

Default Re: How can I click on a joke and have a new joke appear? Part 3 - 09-26-2003 , 03:05 PM



"Evertjan." <exjxw.hannivoort (AT) interxnl (DOT) net> wrote

Quote:
Michael wrote on 25 sep 2003 in comp.lang.javascript:

"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.


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
Sorry. But for some reason, I could not quite get it to work. So I
messed around until I got it to work. Here is what I came up with.


<script>
j=new Array(2)
index = Math.floor(Math.random() * j.length) + 1;
</script>

<div onclick="this.innerHTML=index">Click Here</div>


Now I have another question. I just wanted to take it a step at a
time.

What I really would like to do, is to put each joke into seperate .js
files. Otherwise, since I have hundreds of them it would bog down the
page with too much data and take too long to load into the browser. I
read at www.netmechanic.com where if it takes more than 8 seconds to
load the page then most people will just get bored and go elsewhere.

I have lots of random content and I do not like it when some one has
to reload the whole page to see a different joke or whatever because
it increments the counter. So I thought it would be more convenient if
the person could just click on the joke TEXT and have it display a new
joke each time.

But not just 1 time. Over and over again until they got tired of
reading jokes.

I tried it with an iframe and then just put onclick=location.reload()
in the body tag of the html file in the iframe. That way each time I
clicked on the joke itself the iframe subpage reloaded and displayed a
new joke from the array. It worked great, except that some of the
jokes were larger than the iframe window and then I could not see the
whole thing. I placed each joke in a table, and then gave it a height
and width. But I did not know how to transfer the height and with of
the table in the iframe to the iframe height and width. You know so
that if the table with the joke became larger or smaller the iframe
would resize as needed.

So anyway, I thought there must be an easier way.


Reply With Quote
  #15  
Old   
Michael
 
Posts: n/a

Default Re: How can I click on a joke and have a new joke appear? Part 2 - 09-26-2003 , 03:46 PM



"Evertjan." <exjxw.hannivoort (AT) interxnl (DOT) net> wrote

Quote:
Michael wrote on 25 sep 2003 in comp.lang.javascript:

"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.


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
That script example I last gave you is no good. It just displays the
index number, not the joke in the array. For some reason I cannot get
it to display the joke. If I put this.innerHTML=j[1] it still says
undefined.


Reply With Quote
  #16  
Old   
Evertjan.
 
Posts: n/a

Default Re: How can I click on a joke and have a new joke appear? Part 2 - 09-26-2003 , 04:58 PM



Michael wrote on 26 sep 2003 in comp.lang.javascript:
Quote:
That script example I last gave you is no good. It just displays the
index number, not the joke in the array. For some reason I cannot get
it to display the joke. If I put this.innerHTML=j[1] it still says
undefined.
What script are you talking about ?
Show it again please.

1 are you using IE and what version? or something else ?

2 start debugging:

this.innerHTML="Yes"
alert(j[1])

etc.



--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)


Reply With Quote
  #17  
Old   
Mike Painter
 
Posts: n/a

Default Re: How can I click on a joke and have a new joke appear? Part 2 - 09-26-2003 , 05:06 PM




"Lasse Reichstein Nielsen" <lrn (AT) hotpop (DOT) com> wrote

Quote:
"Mike Painter" <mdotpainter (AT) att (DOT) net> writes:

"Douglas Crockford" <nospam (AT) laserlink (DOT) net> wrote in message
news:bkvlq1$jas$1 (AT) sun-news (DOT) laserlink.net...
snip
That way, you don't have to number the jokes.

Or realize that there are no new jokes.

#751 ?
Odd, I don't hear anybody laughing.
Some people just can't tell a joke.




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.