473,715 Members | 5,223 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

onclick runs straight away....

Hi Gurus

I have the following JS:

var lin1 = document.getEle mentById('amui' );
lin1.onclick = OWi(getimagenam e(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 1314
windandwaves wrote:
Hi Gurus

I have the following JS:

var lin1 = document.getEle mentById('amui' );
lin1.onclick = OWi(getimagenam e(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(getimagenam e(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.getEle mentById('amui' );
lin1.onclick = OWi(getimagenam e(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(getimagenam e(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:
windandwave s wrote:
Hi Gurus

I have the following JS:

var lin1 = document.getEle mentById('amui' );
lin1.onclick = OWi(getimagenam e(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.onclic k = function() { OWi(getimagenam e(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******@hotma il.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
1853
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 question. Anyway... I have a simple javascript function that opens up a new window and writes HTML code in it to display an image (I don't just display the image because of problems with different margins in different browsers). Nothing exotic there. ...
8
3685
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 and passes it two parameters. For the life of me I cannot figure out what the error is, but one occurs everytime I click a &%*$&# radio button. Also, the function only alerts the user immediately as to what question/answer they clicked. I am...
2
14801
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" I want the value "Gallon" to go to session_var
2
7042
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 and onChange handlers do some minor manipulation of form data (although they work on different form elements). If the onChange event fires, I need the form to be submitted. If the onClick event fires for a TR, I also need the form to be...
17
61441
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 programmatically issue a JavaScript statement which causes the browser to act just like the user clicked on a link in my page. And if that link has an onClick JS event defined, I'd want that onClick event to execute too, exactly the same as if the user...
53
81725
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> Clicking on the first list item gives me "link1" because "this" refers
1
6460
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" OnClick="OnSubmit_Click()" runat="server" > </asp:button> If the above is going to fire server side function what is
3
3195
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" onClick="Validate('form_comment_fieldname')">Validate</amainly becuase I do not want to openly show the variables in the browser. In the case of a popup I have this: <a href="#foo" onClick="Validate('http://www.mysite.com/helpdocs/ donotopen/chapter1/index15.html)">Chapter 1 support</a>
17
2678
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 things? Shouldn't they say the same thing?
0
8718
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9340
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9047
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7973
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5967
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4477
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4738
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2539
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2118
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.