function call? 
July 23rd, 2005, 05:36 PM
| | | function call?
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? | 
July 23rd, 2005, 05:36 PM
| | | Re: function call?
Dennis Allen wrote:
[color=blue]
> 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?[/color]
function Outline(oElement, oEvent) {
var sType = oEvent && oEvent.type || "unknown";
alert(sType);
}
....
<a ...
onclick="return Outline(this, event)"
onmouseover="return Outline(this, event)"[color=blue]
>[/color]
ciao, dhgm | 
July 23rd, 2005, 05:36 PM
| | | Re: function call?
Dietmar Meier wrote on 06 feb 2005 in comp.lang.javascript:[color=blue]
> <a ...
> onclick="return Outline(this, event)"
> onmouseover="return Outline(this, event)"[/color]
onclick="return Outline(this, 'onclick')"
onmouseover="return Outline(this, 'onmouseover')"
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress) | 
July 23rd, 2005, 05:36 PM
| | | Re: function call?
Evertjan. wrote:
[color=blue][color=green]
>> <a ...
>> onclick="return Outline(this, event)"
>> onmouseover="return Outline(this, event)"[/color][/color]
[color=blue]
> onclick="return Outline(this, 'onclick')"
> onmouseover="return Outline(this, 'onmouseover')"[/color]
That's no improvement at all.
ciao, dhgm | 
July 23rd, 2005, 05:36 PM
| | | Re: function call?
Dietmar Meier wrote on 06 feb 2005 in comp.lang.javascript:
[color=blue]
> Evertjan. wrote:[color=green][color=darkred]
>>> <a ...
>>> onclick="return Outline(this, event)"
>>> onmouseover="return Outline(this, event)"[/color][/color]
>[color=green]
>> onclick="return Outline(this, 'onclick')"
>> onmouseover="return Outline(this, 'onmouseover')"[/color]
>
> That's no improvement at all.[/color]
I think it is. Simplicity usually wins.
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress) | 
July 23rd, 2005, 05:36 PM
| | | Re: function call?
"Evertjan." wrote[color=blue]
> Dietmar Meier wrote[color=green]
> > Evertjan. wrote:[color=darkred]
> >>> onclick="return Outline(this, event)"
> >>> onmouseover="return Outline(this, event)"[/color]
> >[color=darkred]
> >> onclick="return Outline(this, 'onclick')"
> >> onmouseover="return Outline(this, 'onmouseover')"[/color]
> >
> > That's no improvement at all.[/color]
>
> I think it is. Simplicity usually wins.[/color]
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 | 
July 23rd, 2005, 05:36 PM
| | | Re: function call?
Ivo wrote on 06 feb 2005 in comp.lang.javascript:[color=blue]
> "Evertjan." wrote[color=green]
>> Dietmar Meier wrote[color=darkred]
>> > 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.[/color]
>>
>> I think it is. Simplicity usually wins.[/color]
>
> 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?[/color]
No.
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress) | 
July 23rd, 2005, 05:36 PM
| | | Re: function call?
Evertjan. wrote:
[color=blue][color=green][color=darkred]
>>>> onclick="return Outline(this, event)"
>>>> onmouseover="return Outline(this, event)"[/color][/color][/color]
[color=blue][color=green][color=darkred]
>>> onclick="return Outline(this, 'onclick')"
>>> onmouseover="return Outline(this, 'onmouseover')"[/color][/color][/color]
[color=blue][color=green]
>> That's no improvement at all.[/color][/color]
[color=blue]
> I think it is. Simplicity usually wins.[/color]
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 | 
July 23rd, 2005, 05:38 PM
| | | Re: function call?
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 | 
July 23rd, 2005, 05:38 PM
| | | Re: function call?
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> | 
July 23rd, 2005, 05:38 PM
| | | Re: function call?
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 | 
July 23rd, 2005, 05:38 PM
| | | Re: function call?
I was hoping for a way that didn't involve passing another parameter, but it'll work...Dennis
"eric" <ericcremer@yahoo.com> wrote in message news:1107817797.548584.201450@l41g2000cwc.googlegr oups.com...[color=blue]
> 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
>[/color] | 
July 23rd, 2005, 05:39 PM
| | | Re: function call?
Dennis Allen wrote:[color=blue]
> I was hoping for a way that didn't involve passing another parameter,[/color]
but it'll work...Dennis[color=blue]
>
> "eric" <ericcremer@yahoo.com> wrote in message[/color]
news:1107817797.548584.201450@l41g2000cwc.googlegr oups.com...[color=blue][color=green]
> > 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
> >[/color][/color]
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> | | Thread Tools | Search 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 HTML code is Off | | | | | | What is Bytes?
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 220,989 network members.
|