473,396 Members | 1,938 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

functions without arguments

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.

--
George Hester
__________________________________
Jul 20 '05 #1
2 1437
><.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.


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.

For instance,

<.div onmouseover="alert( 3);">

The function that is attached to the onmouseover event handler looks like this.

function Anonymous() {
alert( 3);
}

You do not attach "alert( 3);" to the onmousover event, you attach an Anonymous
function which contains "alert( 3);".

A more accurate representation of what you are trying to accomplish would be
this.

function Test_MO_Function() {
alert( f( 3));
}

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

document.getElementById( "elmTest").onmouseover = Test_MO_Function;
Peace, Vm
Yaz

Providing complicated solutions to simple problems since 1997.
Jul 20 '05 #2
__________________________________
"to heave chunks" <ju*****@aol.compels.me> wrote in message news:20***************************@mb-m28.aol.com...
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.
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Bhushit Joshipura | last post by:
This post contains one question and one proposal. A. May I know why order of evaluation of arguments is not specified in C/C++? I asked a question in comp.lang.c++ for the following...
99
by: David MacQuigg | last post by:
I'm not getting any feedback on the most important benefit in my proposed "Ideas for Python 3" thread - the unification of methods and functions. Perhaps it was buried among too many other less...
0
by: Anthony Baxter | last post by:
To go along with the 2.4a3 release, here's an updated version of the decorator PEP. It describes the state of decorators as they are in 2.4a3. PEP: 318 Title: Decorators for Functions and...
1
by: optimistx | last post by:
How to build or find an object browser for javascript? E.g. Delphi integrated developement environment ('ide') offers a very practical object browser for Pascal language. When typing a name with...
6
by: Melkor Ainur | last post by:
Hello, I'm attempting to build an interpreter for a pascal-like language. Currently, I don't generate any assembly. Instead, I just build an abstract syntax tree representing what I've parsed...
1
by: S?ren Gammelmark | last post by:
Hi I have been searching the web and comp.lang.c of a method of using variable-argument function pointers and the like. And some of the questions arising in this post are answered partly in...
25
by: Russell | last post by:
I want my code to be Python 3000 compliant, and hear that lambda is being eliminated. The problem is that I want to partially bind an existing function with a value "foo" that isn't known until...
16
by: Martin Jørgensen | last post by:
Hi, Problem: ======== Some of my output functions are beginning to take pretty many arguments... I mean.... We're talking about 10-15 arguments :-) So I thought to myself, perhaps this is...
6
by: Fuzzyman | last post by:
Hello all, I'm trying to extract the code object from a function, and exec it without explicitly passing parameters. The code object 'knows' it expects to receive paramaters. It's 'arg_count'...
6
by: ma740988 | last post by:
I'm perusing a question and curiosity got the best of me in part because I cant solve the problem Consider: typedef unsigned int word_type ; class foo { public: void set_mx_digits_1 (...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.