473,811 Members | 3,026 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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.
Jul 20 '05 #1
16 2240
In article <70************ **************@ posting.google. com>, mdh_2972
@hotmail.com says...
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.


<a href="page.htm" >blah blah blah</a>

--
Hywel I do not eat quiche
http://hyweljenkins.co.uk/
http://hyweljenkins.co.uk/mfaq.php
Jul 20 '05 #2
Michael wrote on 22 sep 2003 in comp.lang.javas cript:
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.i nnerHTML=j[Math.floor(Math .random()*21)]">
Click here for jokes
</div>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 20 '05 #3
Lee
Michael said:

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.


There are many different possibly ways to display random jokes or sayings.

We would need to know how you're doing it to tell you how best to
change it so that it changes when you click on it.

Jul 20 '05 #4
Ron
"Michael" <md******@hotma il.com> wrote in message
news:70******** *************** ***@posting.goo gle.com...
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
it can only change what is on the screen based on what has already been sent
to the browser.

If you send a page of say 10 jokes you could display 1 then the next on
clicking a 'next' button.

a suitable technique is to load each on to its own <div> with a unique ID

<div ID='a' style='visibili ty:hidden;'>
Joke 1
</div>
<div ID='b' style='visibili ty:hidden;'>

Joke 2
</div>
you would be better setting these all in an identical class controlling
absolute position etc.
then on clicking the button use getElementbyID to unhide the next and hide
the previous

On the other hand,
If you want to retrieve from a server you would have to use the script to
modify the URL and fetch the next page but that as you say is reloading the
page.

HTH

Ron.

Jul 20 '05 #5
"Evertjan." <ex************ **@interxnl.net > wrote in message news:<Xn******* *************@1 94.109.133.29>. ..
Michael wrote on 22 sep 2003 in comp.lang.javas cript:
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.i nnerHTML=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.
Jul 20 '05 #6
Michael wrote on 25 sep 2003 in comp.lang.javas cript:
"Evertjan." <ex************ **@interxnl.net > wrote in message
news:<Xn******* *************@1 94.109.133.29>. ..
Michael wrote on 22 sep 2003 in comp.lang.javas cript:
> 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.i nnerHTML=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

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 20 '05 #7
> >> > 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.i nnerHTML=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

Jul 20 '05 #8

"Douglas Crockford" <no****@laserli nk.net> wrote in message
news:bk******** **@sun-news.laserlink. net...
<snip >
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.
Jul 20 '05 #9
Douglas Crockford wrote on 25 sep 2003 in comp.lang.javas cript:
>> 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 !

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 20 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
6142
by: Jim Hubbard | last post by:
By one-click deployment I mean the ability to click on an EXE located on a server (internet or intranet) and run it locally. Due to the default restrictions placed on such code (no file manipulation, no registry manipulation, etc.) what can you accomplish with the code (other than reading and writing to non-local databases)? Almost all functional code requires access to the local file system. I think that most software publishers will...
68
4034
by: Ted Nicols | last post by:
That's what I keep asking myself whenever develop in .NET. Is this a joke a farse or just a bad dream? ..NET is slow, actually slow is just a polite word I can use in a newsgroup. ..NET is just a VM and as one it works very slowly, before and after JIT. I don't understand why some people insist that a VM can be compared with native code. I really feel sick, whenever compare native C++ code against
4
2797
by: Matt Horsey | last post by:
There are two men, an Englishmen and an Australian, wearing their respective cricket uniforms, in the men's room. After finishing up, the English man walks to the sink to wash up. The Aussie man goes directly to the door. The English man speaks up, "In England, we wash our hands after urinating." The Aussie man calls back before exiting, "In Australia we don't piss on our hands."
2
6281
by: Sean | last post by:
Hi, I have a treeview and user can right click the treenodes, depending on the nodes, different shortcut menu will appear. I want only the shortcut menu to appear if the point of the right mouse click is within the label text of the treenode instead of row-wide.
23
442
by: Skybuck Flying | last post by:
Some coders don't need an obfuscator, they are the obfuscator. Bye, Skybuck =D
2
1665
by: mindscreen | last post by:
I want to use Right-Click menu of mouse in any form or anywhere in my program? How can I able to do this? I want that when user right-click on any button or form a special pop-up menu will appear with some extra options, whenever user click any option, it will work. I also want to use the Function Keys in my program. Such as, whenever any user press F1, a new form will appear that describe about the software and help topics. For Function...
2
4264
by: Ed Dror | last post by:
Hi there, Based on Microsoft ASP.NET SDK treeview control binding to northwind database (Categoried, Products) I added the following code Protected Sub TreeView1_SelectedNodeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TreeView1.SelectedNodeChanged Me.TreeView1.SelectedNode.NavigateUrl = Me.TreeView1.SelectedNode.Text + ".aspx"
6
1316
by: charvi | last post by:
hi is there any ascii code for mouse click this is because i have atext box and a list box.when i enter two letters in the text box all the related names will appear in the list box i want to select the name either by using arrow keys and enter key or by mouse click i was possible to code for arrow keys and then when i press enter key the names will appear in text box and list disappears.but when i use mouse click the name will appear in...
8
8502
by: starrysky | last post by:
I have a program which puts an icon in the notification area and has a menu associated with it available by right clicking on the icon. I want the menu items to be selected by single left clicks but I also want the user to be able to single left click on the icon itself to do some other functionality. Here's the problem - the single click on the menu first fires the notifyicon1_click() routine and then the menuitem1_click() routine. How do I...
0
9605
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10386
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10398
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10133
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9204
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6889
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5554
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4339
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3017
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.