functions without arguments

G

George Hester

In my neck of the woods functions usually have arguments. For example f(r) = 3 + r is a nice function. f(5) = 8, f(-3) = 0. In JavaScript we could write it like this:

function f(r){
return (r + 3);
}

easy enough.

Now say we have a <INPUT element that has the onmouseover event defined like this:

<INPUT name="test"... onmouseover="JavaScript:alert(f(3));".../>

When the mouse goes over this elemnt you will get a message box that contains the value 6.

But what if we would like to remove the attribute and assign the onmouseover this way:

<INPUT name="test".../>

<script type="javascript">
<!-- Begin
document.getElementById('test').onmouseover = f
function f(r){
return (r+3);
}
// End -->
</script>

This won't work. I understand why it doesn't but I don't understand if assigning event handlers in this fashion REQUIRES argumentless functions. Is that right? Thanks.
 
G

George Hester

__________________________________
to heave chunks said:
I don't you think you understand this as well as you may think. When you add
an event handler attribute to a HTML tag, the scripting engine attaches an
anonymous function to the event handler.
Peace, Vm
Yaz
Sure that's why I asked. I am not too ashamed to be dumb. It happens. I understand a function I just didn't understand JavaScript's use of it. Thanks Vm I think I can use your hint.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,888
Messages
2,569,964
Members
46,293
Latest member
BonnieHamb

Latest Threads

Top