LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-29-2015, 05:21 AM   #1
rblampain
Senior Member
 
Registered: Aug 2004
Location: Western Australia
Distribution: Debian 11
Posts: 1,288

Rep: Reputation: 52
how can I correctly use onMouseOver in HTML


I have posted a question regarding the onMouseOver event showing the code I used, one of the answers I was given was to
Quote:
"..get rid of the "in-line statements! An HTML declaration is no place for (javascript) 'statements that actually do something!".
The volunteer then gives me the reason behind the logic but my experience is far too low to draw the solution from this explanation. I have searched for answers on the web but all I can find is copies of exactly what I have done although one of those adds below the example that it is not recommended practice. My search on the Internet is also made more difficult because all the examples I have found change something within the same page but I want to change something in another frame (frameset).

Another answer gives a good short solution but a number of "<form></form>" have now been added to the "<td>s of the same document and although the document still validates with the W3C validator, clicking the submit button only calls the browser which cannot find "/cgi-bin/program00x.yab", not the server, so I thing it is probably necessary to clean the code from the beginning.

I think I am advised in the answers to use javascript functions and call them from the HTMl but I am not sure and this seems a lot more work to me than what I have done.

Can anyone point me to examples of correct use?

Thank you for your help.

Here is a section of my code with content removed.

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title>Some title.</title><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><link rel=stylesheet type="text/css" href="css.css"><script type="text/javascript" language="javascript">
</head><body class="blue"><table class="tabl01"><tr><td align="left">
<form method="post" action="/cgi-bin/program001.yab"><input type="submit" value="Submit"></form>
<a name="0"></a><h3></h3>
<p><span class="some style">some name</span></p><hr>
<form method="post" action="/cgi-bin/program002.yab"><input type="submit" value="Submit"></form>
<h2></h2>
<a name="1"></a><h3></h3>
<p>
<a href="#1" onClick="window.status='Explanation about`Some text`'; parent.panl.location='definitions/some text/definition.htm'; return true">Some text</a>
<a href="#1" onClick="window.status='Explanation about`Some text`'; parent.panl.location='definitions/some text/definition.htm'; return true">Some text</a></p><hr> 
<a href="#top" target="panr"><img src="../../imag/indx.gif" alt="Index" align="right"></a>
<form method="post" action="/cgi-bin/program003.yab"><input type="submit" value="Submit"></form>
<a name="2"></a><h3></h3>
<p></p><hr>
<!-- more -->
</td></tr></table></body></html>

Last edited by rblampain; 07-29-2015 at 05:25 AM.
 
Old 07-29-2015, 08:26 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,856
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
For the third time: if you have onclick (not onClick, by the way) then instead of <a> use <span>
 
Old 07-29-2015, 08:31 AM   #3
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 446Reputation: 446Reputation: 446Reputation: 446Reputation: 446
Hi

In a small project, it doesn't matter much if you put javascript in the HTML like you do, or if you call some function. But for a bigger project, you should try to seperate logic/data and it's presentation. It's about how easy it is maintaining things later.

For example, I see you set some text in the status bar. Most modern browsers hide it, so later, you might want to change it to tooltip text instead.

Another example is if you want to get rid of frames. Pages with framesets has a problem. You can't link to a page and expect all the frames to get the right content. Another problem is that clicking back and forward doesn't always work well.

A template system is a solution to these problems. It's usually used by server side scripts, but you can do it with Javascript as well.

Template systems can be complicated - maybe overkill? But it's possible to write it so it's a lot easier to maintain, without using a template system.

Here's an example:

Code:
var cities = [
	{ 
		name : "Paris", 
 		description : "Capital of France",
		picture : "images/paris.png",
		homepage : "http://paris.fr",
		infopage : "paris.html"
	},
	{
		name : "London",
		description : "Capital of Great Britain",
		picture : "images/london.png",
		homepage : "http://london.co.uk",
		infopage : "london.html"		
	}
};

for ( var i=0 ; i<cities.length ; i++ ) {
	var city = cities[i];
	document.write("<span class='cityName' title='" + city.description + "'>" + city.name + "</span>");
	document.write("<img src='" + city.picture + "' onmouseover='showCityInfo(" + i + ")' onmouseout='showCityInfo(0)'>");
	document.write("<a href='" + city.homepage + "'>Go to homepage</a>");
}

function showCityInfo(cityNumber)
{
	if (!cityNumber) {
		//what to do on mouseOut?
	}
	var city = cities[cityNumber];
	// frameset way:
	document.frames.cityInfoFrame.src = city.infopage;
	// or load the info in a div instead:
	$("#cityInfoDiv").load(city.infopage);
}
This is just "pseudocode". But this way, it's a lot easier to change things. You want to try with or without the information in a frame? You can change it in one place and it works for all cities. You don't want the description as tooltip over the name? Again, there's only one place to change that. More cities? More information about each city? Again, it's all easy to change. If this was all HTML with inline javascript to do things, a simple change can be very difficult.
 
1 members found this post helpful.
Old 07-29-2015, 08:42 AM   #4
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 446Reputation: 446Reputation: 446Reputation: 446Reputation: 446
And other tip: Look for libraries that do things for you. If you already have separated the data from the presentation, it's really easy to use something like this:

http://jquerytools.github.io/demos/t.../any-html.html
 
1 members found this post helpful.
Old 07-29-2015, 09:39 AM   #5
rblampain
Senior Member
 
Registered: Aug 2004
Location: Western Australia
Distribution: Debian 11
Posts: 1,288

Original Poster
Rep: Reputation: 52
To NevemTeve
Sorry to upset you, this is another case when onclick is not the problem. In another html document where it was a problem, I used <span as you suggested and it works fine.

Last edited by rblampain; 07-29-2015 at 09:50 AM.
 
Old 07-29-2015, 09:43 AM   #6
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,219

Rep: Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309
Quote:
all the examples I have found change something within the same page but I want to change something in another frame (frameset).
Google got me this, but I haven't tried it:

http://stackoverflow.com/a/1807739

Last edited by dugan; 07-29-2015 at 12:02 PM.
 
1 members found this post helpful.
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I disable onClick of onMouseOver/Out rblampain Programming 6 06-30-2015 03:36 AM
onMouseOver question rblampain Programming 3 01-06-2011 07:11 AM
[SOLVED] Wicd won't install correctly/run correctly (64-bit Slackware 13) bgraybr Slackware 3 04-01-2010 06:57 PM
onMouseOver/onMouseOut question rblampain Programming 2 02-28-2008 07:09 AM
Search & Replace Technique to Fix html HREFs w/o html extension donv2 Linux - Newbie 1 01-30-2007 11:59 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:28 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration