473,386 Members | 1,693 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,386 software developers and data experts.

onclick runs straight away....

Hi Gurus

I have the following JS:

var lin1 = document.getElementById('amui');
lin1.onclick = OWi(getimagename(mouseOvers[i1].src));

the onclick command executes straight away (before I click on the amui
element). What can I do about this? I dont understand it at all...

TIA

Nicolaas
Feb 18 '06 #1
6 1296
windandwaves wrote:
Hi Gurus

I have the following JS:

var lin1 = document.getElementById('amui');
lin1.onclick = OWi(getimagename(mouseOvers[i1].src));

the onclick command executes straight away (before I click on the amui
element). What can I do about this? I dont understand it at all...

You aren't assigning a function to onclick, you are calling the function
and assigning the result!

Assuming OWi the the function you wish to call,

lin1.onclick = function() { OWi(getimagename(mouseOvers[i1].src)); };

--
Ian Collins.
Feb 18 '06 #2
Try putting the JS in <head></head> portion.

Feb 19 '06 #3
Ian Collins wrote:
windandwaves wrote:
Hi Gurus

I have the following JS:

var lin1 = document.getElementById('amui');
lin1.onclick = OWi(getimagename(mouseOvers[i1].src));

the onclick command executes straight away (before I click on the
amui element). What can I do about this? I dont understand it at
all...

You aren't assigning a function to onclick, you are calling the
function and assigning the result!

Assuming OWi the the function you wish to call,

lin1.onclick = function() { OWi(getimagename(mouseOvers[i1].src)); };


Great - thank you Ian. It starts to make sense.
Feb 20 '06 #4
sh************@gmail.com wrote:
Try putting the JS in <head></head> portion.

What are you replying to? Please quote.

--
Ian Collins.
Feb 20 '06 #5
windandwaves wrote:
Ian Collins wrote:
windandwaves wrote:
Hi Gurus

I have the following JS:

var lin1 = document.getElementById('amui');
lin1.onclick = OWi(getimagename(mouseOvers[i1].src));

the onclick command executes straight away (before I click on the
amui element). What can I do about this? I dont understand it at
all...


You aren't assigning a function to onclick, you are calling the
function and assigning the result!

Assuming OWi the the function you wish to call,

lin1.onclick = function() { OWi(getimagename(mouseOvers[i1].src)); };

Great - thank you Ian. It starts to make sense.


Good! What you had is a very common mistake.

--
Ian Collins.
Feb 20 '06 #6
que significa eso de el hilo de rosca
En Lun, Feb 20 2006 10:06:26 am +0000, Ian Collins <ia******@hotmail.com> dice:
sh************@gmail.com wrote:
Try putting the JS in <head></head> portion.

What are you replying to? Please quote.

--
Ian Collins.

May 21 '06 #7

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

Similar topics

2
by: Graham J | last post by:
Hello, Apologies for the somewhat wordy and garbled subject as I couldn't think how to phrase it and this has hindered my searching for any previous answers. It could be a really simple...
8
by: Shock | last post by:
Hello everyone, I am having a problem with the program below. I have isolated the problem to the onclick event that is located throughout arrQuestions. The onclick event refers to a function...
2
by: Galsaba | last post by:
How can I send back an argumet with "onClick"? <a href=test.php onClick="checkLink ('Gallon')" > 1 Gallon</a> function checkLink(a) { return (a+3) } When the user click on the word "Gallon"...
2
by: Andy Goldstein | last post by:
I have a table where all the TRs have an onClick handler registered. One (and only one) of the rows has 2 text input boxes, where each textbox has an onChange handler registered. Both the onClick...
17
by: Mike Gratee | last post by:
Is it possible to use JavaScript to cause the browser to click a link on a page and have the browser act exactly like the user had clicked on the link directly? In other words, I need to...
53
by: usenet | last post by:
See <ul> <li><a name="link1" onClick="alert(this.name);return false;" href="#">Link1</a></li> <li><a name="link2" href="javascript:alert(this);">Link2</a></li> <li>Item 3</li> </ul> ...
1
by: Krishna | last post by:
1. What is the difference between OnClick and OnServerClick in web button control If I have a asp button control as follows <asp:button id="SubmitOrder" Text="Submit Order"...
3
by: eelco.v987 | last post by:
Hello, I am buildig a website, which uses javascript for several features such as fieldvalidation, popupwindows etc. Currently I am using <a href="#foo"...
17
by: yawnmoth | last post by:
http://www.frostjedi.com/terra/scripts/demo/this-alert.html http://www.frostjedi.com/terra/scripts/demo/this-alert2.html Why, when you click in the black box, do the alert boxes say different...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.