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

Help needed for writing some javascript code

Does anyone know how to create a link (<a> . . . </a>) with some piece
of javascript code that has
the onClick event set for some function that I also wrote (not a
build-in function).

I can find all sorts of samples in these disc.groups but none of them
seems to work for me.

I am focussed on Firefox, but some code that also works for IE, would
be appreciated.

BTW I know how to create elements in the html document, that is not the
problem. The problem
is that I seem not te be able to set the onClick event for some created
element. I tried for both
a link and also for a text-element.
I can set the onClick for some built-in function like alert('Nice
Day').
There are loads of examples to
be found for that, and they indeed work.

Thanks in advance,

André Lagerburg

Jun 23 '06 #1
2 1318
Maybe you could try something like that:

function link_clicked()
{
....
}

newlink.onclick = link_clicked;

I havent tested it though. Not sure if it works.

an*************@wanadoo.nl escreveu:
Does anyone know how to create a link (<a> . . . </a>) with some piece
of javascript code that has
the onClick event set for some function that I also wrote (not a
build-in function).

I can find all sorts of samples in these disc.groups but none of them
seems to work for me.

I am focussed on Firefox, but some code that also works for IE, would
be appreciated.

BTW I know how to create elements in the html document, that is not the
problem. The problem
is that I seem not te be able to set the onClick event for some created
element. I tried for both
a link and also for a text-element.
I can set the onClick for some built-in function like alert('Nice
Day').
There are loads of examples to
be found for that, and they indeed work.

Thanks in advance,

André Lagerburg


Jun 23 '06 #2
an*************@wanadoo.nl writes:
Does anyone know how to create a link (<a> . . . </a>) with some
piece of javascript code that has the onClick event set for some
function that I also wrote (not a build-in function).


var a = document.createElement("a");
// add attributes
// then either:
a.onclick = myFunction;
// or
if (a.addEventHandler) {
a.addEventHandler("click", myFunction, false);
} else if (a.attachEvent) {
a.attachEvent("onclick", myFunction);
}

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jun 23 '06 #3

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

Similar topics

8
by: Johnny Knoxville | last post by:
I've added a favicon to my site (http://lazyape.filetap.com/) which works fine if you add the site to favourites the normal way, but I have some JavaScript code on a couple of pages with a link,...
1
by: Rob | last post by:
Hi everyone, I'm having some big JS problems - my function is making my html code vanish, and I need help! Here's the code, try it for yourself. You'll notice that when you click either links...
2
by: Targa | last post by:
Im using the code below to pop up a window: It works fine except for that in the titlebar, my domain name is listed before the page title like below: http://mydomain.com - MyPopupwindowname -...
0
by: Michael L | last post by:
Hi Guys(I apologize for the lengty post - Im trying to explain it as best i can) I've been cracking my head on this one for the past 24+ hours and i have tried creating the function in ten...
32
by: Tom Cole | last post by:
I bet 50% of the posts I've read lately have had at least one bad thing to say about every website or book dedicated to javascript. There are clearly a few posters (you know who you are) who...
2
by: Ken1 | last post by:
Hello, I want to upgrade my form filling process and make it user interactive. From what i've been reading i guess I need to use AJAX for this to work. I want to do simple stuff like user entering...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
4
by: dupdupdup | last post by:
Hello there, im needed to develop a gallery for this website. im using hotspots to go to my frames in my flash Each hotspot goes to each frame. The flash is loaded properly. When i right click...
53
by: souporpower | last post by:
Hello All I am trying to activate a link using Jquery. Here is my code; <html> <head> <script type="text/javascript" src="../../resources/js/ jquery-1.2.6.js"</script> <script...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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: 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...

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.