473,699 Members | 2,514 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

onClick event problem

Hello.
I am trying to set the onclick event for images through a function, but the
event is triggered as soon the page loads, then will not work when the image
is clicked. Can anyone suggest what is wrong?
It is happening in both IE6 and Firefox
---------------------------------------------------------------------------
window.onload = fnNewWindowLink s;

function fnNewWindowLink s() {
for (var intLinks=0; intLinks<docume nt.links.length ; intLinks++) {
if (document.links[intLinks].className == "picture") {
document.links[intLinks].onClick = alert("Clicked" );
}
}
}
---------------------------------------------------------------------------
Regards
Dec 26 '06 #1
5 2099
Magician said the following on 12/25/2006 8:18 PM:
Hello.
I am trying to set the onclick event for images through a function, but the
event is triggered as soon the page loads, then will not work when the image
is clicked. Can anyone suggest what is wrong?
It is happening in both IE6 and Firefox
---------------------------------------------------------------------------
window.onload = fnNewWindowLink s;

function fnNewWindowLink s() {
for (var intLinks=0; intLinks<docume nt.links.length ; intLinks++) {
if (document.links[intLinks].className == "picture") {
document.links[intLinks].onClick = alert("Clicked" );
Two things:

It is onclick in JS, not onClick
document.links[intLinks].onclick= new Function('alert ("Clicked")' )

--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Dec 26 '06 #2

"Randy Webb" <Hi************ @aol.comwrote in message
news:A4******** ************@te lcove.net...
Magician said the following on 12/25/2006 8:18 PM:
>Hello.
I am trying to set the onclick event for images through a function, but
the
event is triggered as soon the page loads, then will not work when the
image
is clicked. Can anyone suggest what is wrong?
It is happening in both IE6 and Firefox
---------------------------------------------------------------------------
window.onloa d = fnNewWindowLink s;

function fnNewWindowLink s() {
for (var intLinks=0; intLinks<docume nt.links.length ; intLinks++) {
if (document.links[intLinks].className == "picture") {
document.links[intLinks].onClick = alert("Clicked" );

Two things:

It is onclick in JS, not onClick
document.links[intLinks].onclick= new Function('alert ("Clicked")' )

--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices -
http://www.JavascriptToolbox.com/bestpractices/

Thanks Randy, I got that working, but when i try to extend it a bit further
to open an image in a window, it is going back to loading the window when
the page loads and not on the click event.
I am following examples is a js book and trying to adapt them for my
purposes but I can't get it working.
Is my problem now the call to the second function?

----------------------
window.onload = fnNewWindowLink s;

function fnNewWindowLink s() {
for (var intLinks=0; intLinks<docume nt.links.length ; intLinks++) {
if (document.links[intLinks].className == "picture") {
document.links[intLinks].onclick = fnNewWindow() ;
}
}
}

function fnNewWindow() {
var strImage = "creative/artwork/" + this.id + ".jpg";
var objWindow = window.open(str Image, "PictureWindow" ,"resizable=yes ");
return false;
}
---------------------------
Regards
Mag
Dec 26 '06 #3
Thanks but I worked it out after 3 hours of trial and error. just leave the
() off the function call and it works!
Thanks anyway :)

mag

"Magician" <.wrote in message
news:45******** *************** @per-qv1-newsreader-01.iinet.net.au ...
>
"Randy Webb" <Hi************ @aol.comwrote in message
news:A4******** ************@te lcove.net...
>Magician said the following on 12/25/2006 8:18 PM:
>>Hello.
I am trying to set the onclick event for images through a function, but
the
event is triggered as soon the page loads, then will not work when the
image
is clicked. Can anyone suggest what is wrong?
It is happening in both IE6 and Firefox
---------------------------------------------------------------------------
window.onlo ad = fnNewWindowLink s;

function fnNewWindowLink s() {
for (var intLinks=0; intLinks<docume nt.links.length ; intLinks++) {
if (document.links[intLinks].className == "picture") {
document.links[intLinks].onClick = alert("Clicked" );

Two things:

It is onclick in JS, not onClick
document.lin ks[intLinks].onclick= new Function('alert ("Clicked")' )

--
Randy
Chance Favors The Prepared Mind
comp.lang.java script FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices -
http://www.JavascriptToolbox.com/bestpractices/


Thanks Randy, I got that working, but when i try to extend it a bit
further to open an image in a window, it is going back to loading the
window when the page loads and not on the click event.
I am following examples is a js book and trying to adapt them for my
purposes but I can't get it working.
Is my problem now the call to the second function?

----------------------
window.onload = fnNewWindowLink s;

function fnNewWindowLink s() {
for (var intLinks=0; intLinks<docume nt.links.length ; intLinks++) {
if (document.links[intLinks].className == "picture") {
document.links[intLinks].onclick = fnNewWindow() ;
}
}
}

function fnNewWindow() {
var strImage = "creative/artwork/" + this.id + ".jpg";
var objWindow = window.open(str Image, "PictureWindow" ,"resizable=yes ");
return false;
}
---------------------------
Regards
Mag

Dec 26 '06 #4
Magician wrote:

Is my problem now the call to the second function?

----------------------
window.onload = fnNewWindowLink s;

function fnNewWindowLink s() {
for (var intLinks=0; intLinks<docume nt.links.length ; intLinks++) {
if (document.links[intLinks].className == "picture") {
document.links[intLinks].onclick = fnNewWindow() ;
}
}
}

function fnNewWindow() {
var strImage = "creative/artwork/" + this.id + ".jpg";
var objWindow = window.open(str Image, "PictureWindow" ,"resizable=yes ");
return false;
}
function fnNewWindowLink s() {
var D=document.link s,DL=Dlength;
for (var intLinks=0; intLinks<DL; intLinks++) {
if (D[intLinks].className == "picture") {
D[intLinks].onclick = function(){
objWindow =
window.open(
"creative/artwork/" + this.id + ".jpg",
"PictureWindow" +intLinks,
"resizable=yes" );
}
}
}
}

onload=fnNewWin dowLinks;

Mick
Dec 26 '06 #5
ASM
Magician a écrit :
Thanks but I worked it out after 3 hours of trial and error. just leave the
() off the function call and it works!
document.links[intLinks].onclick= function(){
alert('Clicked' );
return false;
};


--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Dec 27 '06 #6

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

Similar topics

8
3683
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...
6
9937
by: Cockroach | last post by:
Hello, I have a problem where the onClick of a table row will activates a window.location event, and inside a cell in that row, an image onClick event shows/hides a div. The problem is that when you click on the image, it briefly shows the div, and then reloads the page to the window.location url. Is there a way of preventing the onClick of the row (<tr>) from doing
5
2580
by: moondaddy | last post by:
I have a <a> element in a datagrid which wraps some asp.net labels. this element also has an onclick event which does not fire in netscape 6 (and perhaps other browsers for all I know...). Below is the code for this. the onclick event calls a javascript function which I put an alert in the firt line to tell me if its working. It does work in IE. Any ideas on how to get netcrap... oops, I'm sorry, netscape to fire the onclick event? ...
11
3022
by: GaryB | last post by:
Hi Guys, I've been battling with this one for hours - I hope that you can help me! My code modifies the <aon a page, from a standard document link into a link with a tailored onclick event. It works perfectly (assigning the correct images and the correct onclick events to the correct <atags):
14
14605
by: teddysnips | last post by:
WINDOWS FORMS I've a form that has a textbox that allows the user to enter a string. On the LostFocus event, the textbox formats the string into a preferred format. However, if the user presses the "Save" button while the textbox has the focus, the LostFocus code doesn't run at the right time, so that the "Save" function is dealing with an incorrectly formatted string and the whole caboodle goes splat.
4
13557
by: sameergn | last post by:
Hi, I have an image in my HTML form which has onclick() handler. There is also a submit button and a text box. Whenever text box has focus and user presses enter, the onclick() event of image is fired with event.keyCode as undefined. I was expecting that the form would get submitted. I tried returning from onclick() handler if keyCode is null, but the
5
13946
by: Stuart Shay | last post by:
Hello All I am working on ASP.NET 1.1 Custom Pager that allows a User to Enter a Number in a TextBox and go to the page selected. Since the OnClick Event does not work in ASP.NET 1.1 for a TextBox I want to use a hidden button to fire when the Onclick Event is fired for the TextBox.
3
6502
by: Michael_R_Banks | last post by:
I'm trying to dynamically build a table that allows users to remove rows when they click a corresponding button. For some reason, whenever I add the button to the table, it never fires the onclick event. I'm stumped with this one, any assistance would be appreciated. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:// www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"...
18
3937
by: joaotsetsemoita | last post by:
Hello everyone, I'm having troubles assigning an onclick event to a cell. Im trying something like cursorPoint.cells.style.cursor = "hand"; cursorPoint.cells.width = "20"; cursorPoint.cells.onclick = "alert('this is a test');" cursorPoint.cells.alt = "Select the columns"; cursorPoint.cells.innerHTML = "&nbsp;"
2
2742
by: DavidGeorge | last post by:
In an earlier thread I recounted a problem I was having, but it took a while to reduce the problem to it's basic components and the issue became somewhat confused in reaching that point. I hope you will excuse me for bringing it up again but this issue is very frustrating. I created a new form in a brand new (Access 2003) database. This example does nothing useful other than to illustrate the problem. I've explained what I want to do in...
0
9174
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
9035
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8914
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6534
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5875
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
4376
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
4629
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2347
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2009
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.