By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,702 Members | 1,760 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,702 IT Pros & Developers. It's quick & easy.

function call?

P: n/a
Hi. Question. Say I have <a onclick=' return Outline(this)' onmouseover=' return Outline(this)'>. How could I determine in Outline() that it was launched from a mouseover, as opposed to onclick?
Jul 23 '05 #1
Share this Question
Share on Google+
12 Replies


P: n/a
Dennis Allen wrote:
Hi. Question. Say I have <a onclick=' return Outline(this)'
onmouseover=' return Outline(this)'>. How could I determine in
Outline() that it was launched from a mouseover, as opposed to
onclick?
function Outline(oElement, oEvent) {
var sType = oEvent && oEvent.type || "unknown";
alert(sType);
}
....
<a ...
onclick="return Outline(this, event)"
onmouseover="return Outline(this, event)"


ciao, dhgm
Jul 23 '05 #2

P: n/a
Dietmar Meier wrote on 06 feb 2005 in comp.lang.javascript:
<a ...
onclick="return Outline(this, event)"
onmouseover="return Outline(this, event)"


onclick="return Outline(this, 'onclick')"
onmouseover="return Outline(this, 'onmouseover')"
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Jul 23 '05 #3

P: n/a
Evertjan. wrote:
<a ...
onclick="return Outline(this, event)"
onmouseover="return Outline(this, event)"
onclick="return Outline(this, 'onclick')"
onmouseover="return Outline(this, 'onmouseover')"


That's no improvement at all.

ciao, dhgm
Jul 23 '05 #4

P: n/a
Dietmar Meier wrote on 06 feb 2005 in comp.lang.javascript:
Evertjan. wrote:
<a ...
onclick="return Outline(this, event)"
onmouseover="return Outline(this, event)"

onclick="return Outline(this, 'onclick')"
onmouseover="return Outline(this, 'onmouseover')"


That's no improvement at all.


I think it is. Simplicity usually wins.
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Jul 23 '05 #5

P: n/a
Ivo
"Evertjan." wrote
Dietmar Meier wrote
Evertjan. wrote:
onclick="return Outline(this, event)"
onmouseover="return Outline(this, event)"

onclick="return Outline(this, 'onclick')"
onmouseover="return Outline(this, 'onmouseover')"


That's no improvement at all.


I think it is. Simplicity usually wins.


Right, and passing the event with all event handlers is simpler than
hard-coding a different string with every mouseover, click and whathaveyou,
wouldn't you think?
--
Ivo
Jul 23 '05 #6

P: n/a
Ivo wrote on 06 feb 2005 in comp.lang.javascript:
"Evertjan." wrote
Dietmar Meier wrote
> Evertjan. wrote:
>>> onclick="return Outline(this, event)"
>>> onmouseover="return Outline(this, event)"
>
>> onclick="return Outline(this, 'onclick')"
>> onmouseover="return Outline(this, 'onmouseover')"
>
> That's no improvement at all.


I think it is. Simplicity usually wins.


Right, and passing the event with all event handlers is simpler than
hard-coding a different string with every mouseover, click and
whathaveyou, wouldn't you think?


No.
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Jul 23 '05 #7

P: n/a
Evertjan. wrote:
onclick="return Outline(this, event)"
onmouseover="return Outline(this, event)" onclick="return Outline(this, 'onclick')"
onmouseover="return Outline(this, 'onmouseover')"
That's no improvement at all.
I think it is. Simplicity usually wins.


It's not "simple" to write down a string that's already present
as a property of the event object, nor is it "simple" to write
different code for different event handlers where a versatile
variant can be just copied&pasted.

Beyond that you make it harder to maintain: if I have a typo
like "return Outline(this, ebent)", I will most likely get an
error or exeption in this very line, e.g. telling me that there
is no such property. If you have a typo like "return Outline(
this, 'onclock')", you'll most likely get unexpected behaviour
in the function Outline(), thus not in the typo's place.

ciao, dhgm
Jul 23 '05 #8

P: n/a
How about something like:
<script>
function myfun(good,stuff){
if (stuff.type=="click") theevent="click event"
if (stuff.type=="mouseover") theevent="mouse over event"
alert(theevent)
}
</script>

<a id="fred" href="urlhere" onclick="myfun(this,event)"
onmouseover="myfun(this,event)" >Object stuff</a>

further details at:
http://www.webreference.com/js/column9/index.html

Jul 23 '05 #9

P: n/a
How about something like:
<script>
function myfun(good,stuff){
if (stuff.type=="click") theevent="click event"
if (stuff.type=="mouseover") theevent="mouse over event"
alert(theevent)
}
</script>

<a id="fred" href="urlhere" onclick="myfun(this,event)"
onmouseover="myfun(this,event)" >Object stuff</a>

Jul 23 '05 #10

P: n/a
Hi,
Howabout something like this:

<script>
function myfun(good,stuff){
if (stuff.type=="click") theevent="click event"
if (stuff.type=="mouseover") theevent="mouse over event"
alert(theevent)
}
</script>

<a id="fred" href="urlhere" onclick="myfun(this,event)"
onmouseover="myfun(this,event)" >Object stuff</a>

For (lots of ) details and browser compatibility check out:
http://www.webreference.com/js/column9/index.html

Jul 23 '05 #11

P: n/a
I was hoping for a way that didn't involve passing another parameter, but it'll work...Dennis

"eric" <er********@yahoo.com> wrote in message news:11**********************@l41g2000cwc.googlegr oups.com...
Hi,
Howabout something like this:

<script>
function myfun(good,stuff){
if (stuff.type=="click") theevent="click event"
if (stuff.type=="mouseover") theevent="mouse over event"
alert(theevent)
}
</script>

<a id="fred" href="urlhere" onclick="myfun(this,event)"
onmouseover="myfun(this,event)" >Object stuff</a>

For (lots of ) details and browser compatibility check out:
http://www.webreference.com/js/column9/index.html

Jul 23 '05 #12

P: n/a
Dennis Allen wrote:
I was hoping for a way that didn't involve passing another parameter, but it'll work...Dennis
"eric" <er********@yahoo.com> wrote in message

news:11**********************@l41g2000cwc.googlegr oups.com...
Hi,
Howabout something like this:

<script>
function myfun(good,stuff){
if (stuff.type=="click") theevent="click event"
if (stuff.type=="mouseover") theevent="mouse over event"
alert(theevent)
}
</script>

<a id="fred" href="urlhere" onclick="myfun(this,event)"
onmouseover="myfun(this,event)" >Object stuff</a>

For (lots of ) details and browser compatibility check out:
http://www.webreference.com/js/column9/index.html


Just for the sake of argument....

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>untitled</title>
<style type="text/css">

a {
width: 100px;
}
#t {
width: 100%;
height: 560px;
border: none;
font: 11px monospace;
}

</style>
<script type="text/javascript">

function Outline(e)
{
e = e || window.event;
if (e && (txt = document.getElementById('t')))
{
var p, c = [];
for (p in e)
c.push(p + ' ---> ' + e[p]);
txt.value = c.join('\n');
}
}

window.onload = function()
{
document.getElementById('t').value = '';
if (a = document.getElementsByTagName('a').item(0))
{
a.onmouseover = Outline;
a.onmouseout = Outline;
}
}

</script>
</head>
<body>
<a href="#">hoo-hah</a>
<textarea id="t"></textarea>
</body>
</html>

Jul 23 '05 #13

This discussion thread is closed

Replies have been disabled for this discussion.