Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-28-2012, 10:47 PM   PM User | #1
turtleflame
New to the CF scene

 
Join Date: Dec 2012
Posts: 7
Thanks: 1
Thanked 0 Times in 0 Posts
turtleflame is an unknown quantity at this point
Can anyone help me to get onclick to work?

Can anyone help me to get onclick to work? I keep getting a mouse over instead. Do you know what I'm doing wrong? I checked the error console but I have no idea what to do with the information. Here's the code I'm using:

Code:
<!DOCTYPE html>
<html>
<head>
<title>onclick Demo</title>
</head>
<body>
<img src="Picture 322.png" 
onclick="this.title='New Title';" /> 
</body
</html>
Thanks
turtleflame is offline   Reply With Quote
Old 12-28-2012, 11:15 PM   PM User | #2
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,437
Thanks: 52
Thanked 453 Times in 451 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
"this" refers to the element that is receiving the event, in this case the img

so your code is doing exactly what it should.

are you trying to change the title of the document?
xelawho is offline   Reply With Quote
Old 12-28-2012, 11:17 PM   PM User | #3
turtleflame
New to the CF scene

 
Join Date: Dec 2012
Posts: 7
Thanks: 1
Thanked 0 Times in 0 Posts
turtleflame is an unknown quantity at this point
I want "New Title" to pop up when I click on the image but instead "New Title" pops up when I roll over the image and nothing happens when I click.
turtleflame is offline   Reply With Quote
Old 12-28-2012, 11:18 PM   PM User | #4
turtleflame
New to the CF scene

 
Join Date: Dec 2012
Posts: 7
Thanks: 1
Thanked 0 Times in 0 Posts
turtleflame is an unknown quantity at this point
No, I'm not trying to change the title. "New Title" is the title for right now.
turtleflame is offline   Reply With Quote
Old 12-28-2012, 11:21 PM   PM User | #5
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,198
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Yes? Again, it's doing what you told it to do. It is *CHANGING* the title of the image. Which is, indeed, the title that shows up when you mouse over the image.

What do you mean by "want [the title] to pop up"?

You could just do
Code:
<img src="Picture 322.png" onclick="alert('New Title');" />
but alert is very much obsolete nowadays. Some browsers allow the user to block alerts, so they are *NOT* a good way of giving messages.

So what kind of (other) pop up are you interested in?
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 12-28-2012, 11:22 PM   PM User | #6
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,198
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Quote:
Originally Posted by turtleflame View Post
No, I'm not trying to change the title. "New Title" is the title for right now.
No, it is not. At least not until you click on the image. Then it is.

As your code is now, if you roll over the image *BEFORE* you click on it, you will see nothing. No title.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 12-28-2012, 11:22 PM   PM User | #7
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,437
Thanks: 52
Thanked 453 Times in 451 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
that's exactly the behaviour of the tooltip that comes as standard with the "title" attribute.

if you want something like you are talking about I think you will have to build it yourself
xelawho is offline   Reply With Quote
Old 12-28-2012, 11:24 PM   PM User | #8
turtleflame
New to the CF scene

 
Join Date: Dec 2012
Posts: 7
Thanks: 1
Thanked 0 Times in 0 Posts
turtleflame is an unknown quantity at this point
I just want it to do the same thing it does when I roll over the image with my mouse I just don't want the title to show unless I clicked on the image. I'm new so maybe I'm misunderstanding onclick. I don't know.
turtleflame is offline   Reply With Quote
Old 12-28-2012, 11:26 PM   PM User | #9
Nile
Regular Coder

 
Nile's Avatar
 
Join Date: Jun 2008
Posts: 280
Thanks: 2
Thanked 46 Times in 46 Posts
Nile is an unknown quantity at this point
Indeed, you've misunderstood onclick. Search google for "javascript tooltips" and you'll get what you wanted.
Nile is offline   Reply With Quote
Old 12-28-2012, 11:27 PM   PM User | #10
turtleflame
New to the CF scene

 
Join Date: Dec 2012
Posts: 7
Thanks: 1
Thanked 0 Times in 0 Posts
turtleflame is an unknown quantity at this point
Okay thank you.
turtleflame is offline   Reply With Quote
Old 12-28-2012, 11:41 PM   PM User | #11
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,198
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
I disagree. I think he understands oncliick. He just doesn't understand what HTML ALONE does.

He doesn't seem to be aware that rolling over an image *WILL* produce the title display.

As I noted, he could use alert( ) for this except that it's so obsolete. But for his purposes, that may be perfectly okay.

Creating a full blown tooltip is a lot more work. Though there are ways to make it simpler.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

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

Forum Jump


All times are GMT +1. The time now is 12:54 AM.


Advertisement
Log in to turn off these ads.