473,573 Members | 2,686 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Assign onclick event to a Cell

Hello everyone,

I'm having troubles assigning an onclick event to a cell. Im trying
something like

cursorPoint.cel ls[3].style.cursor = "hand";
cursorPoint.cel ls[3].width = "20";
cursorPoint.cel ls[3].onclick = "alert('thi s is a test');"
cursorPoint.cel ls[3].alt = "Select the columns";
cursorPoint.cel ls[3].innerHTML = " "

Everything is just working fine except the onclick. I also tried:

cursorPoint.cel ls[3].click = "alert('thi s is a test');" (without the
"on") but also didnt work.

Any help would be much appreciated

Thanks in advance

Joao

May 9 '07 #1
18 3923
On May 9, 9:52 am, joaotsetsemo... @gmail.com wrote:
Hello everyone,

I'm having troubles assigning an onclick event to a cell. Im trying
something like

cursorPoint.cel ls[3].style.cursor = "hand";
cursorPoint.cel ls[3].width = "20";
cursorPoint.cel ls[3].onclick = "alert('thi s is a test');"
cursorPoint.cel ls[3].alt = "Select the columns";
cursorPoint.cel ls[3].innerHTML = " "

Everything is just working fine except the onclick. I also tried:

cursorPoint.cel ls[3].click = "alert('thi s is a test');" (without the
"on") but also didnt work.

Any help would be much appreciated

Thanks in advance

Joao
Try this:

addEvent:functi on(obj, evtype, func){
try{
if(window.attac hEvent){
obj.attachEvent ("on"+evtype , func);
}
if(window.addEv entListener){
obj.addEventLis tener(evtype, func,false);
}
}catch(e){
//alert the error if you want
}
}

obj will be the cell, evtype will be click and func will be whatever
function you want called when the event occurs. You also need to keep
in mind that the function will have the event for a parameter but from
the event you can find the source of the event. Let me know if this
does not work for you.

May 9 '07 #2
On May 9, 3:39 pm, Mister Joe <mrjoefri...@gm ail.comwrote:
On May 9, 9:52 am, joaotsetsemo... @gmail.com wrote:


Hello everyone,
I'm having troubles assigning an onclick event to a cell. Im trying
something like
cursorPoint.cel ls[3].style.cursor = "hand";
cursorPoint.cel ls[3].width = "20";
cursorPoint.cel ls[3].onclick = "alert('thi s is a test');"
cursorPoint.cel ls[3].alt = "Select the columns";
cursorPoint.cel ls[3].innerHTML = "&nbsp;"
Everything is just working fine except the onclick. I also tried:
cursorPoint.cel ls[3].click = "alert('thi s is a test');" (without the
"on") but also didnt work.
Any help would be much appreciated
Thanks in advance
Joao

Try this:

addEvent:functi on(obj, evtype, func){
try{
if(window.attac hEvent){
obj.attachEvent ("on"+evtype , func);
}
if(window.addEv entListener){
obj.addEventLis tener(evtype, func,false);
}
}catch(e){
//alert the error if you want
}
}

obj will be the cell, evtype will be click and func will be whatever
function you want called when the event occurs. You also need to keep
in mind that the function will have the event for a parameter but from
the event you can find the source of the event. Let me know if this
does not work for you.- Hide quoted text -

- Show quoted text -
Hi Joe,

thanks for your reply.

Where do i have to put that piece of code? Do I have to call that
function somewhere in my code? What do I have to change in my code?

Btw, I will have plenty of cells to assing onClick events and not only
one.

May 9 '07 #3
ASM
jo************* @gmail.com a écrit :
Hello everyone,

I'm having troubles assigning an onclick event to a cell. Im trying
something like

cursorPoint.cel ls[3].style.cursor = "hand";
cursorPoint.cel ls[3].width = "20";
cursorPoint.cel ls[3].onclick = "alert('thi s is a test');"
cursorPoint.cel ls[3].onclick = function() { alert('this is a test'); };
cursorPoint.cel ls[3].alt = "Select the columns";
cursorPoint.cel ls[3].innerHTML = "&nbsp;"

Everything is just working fine except the onclick. I also tried:

take care that 'cursorPoint' is really what you try to reach
a TD with an ID
cursorPoint = document.getEle mentById('curso rPointTd');

--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
May 9 '07 #4
On May 9, 10:53 am, joaotsetsemo... @gmail.com wrote:
On May 9, 3:39 pm, Mister Joe <mrjoefri...@gm ail.comwrote:
On May 9, 9:52 am, joaotsetsemo... @gmail.com wrote:
Hello everyone,
I'm having troubles assigning an onclick event to a cell. Im trying
something like
cursorPoint.cel ls[3].style.cursor = "hand";
cursorPoint.cel ls[3].width = "20";
cursorPoint.cel ls[3].onclick = "alert('thi s is a test');"
cursorPoint.cel ls[3].alt = "Select the columns";
cursorPoint.cel ls[3].innerHTML = "&nbsp;"
Everything is just working fine except the onclick. I also tried:
cursorPoint.cel ls[3].click = "alert('thi s is a test');" (without the
"on") but also didnt work.
Any help would be much appreciated
Thanks in advance
Joao
Try this:
addEvent:functi on(obj, evtype, func){
try{
if(window.attac hEvent){
obj.attachEvent ("on"+evtype , func);
}
if(window.addEv entListener){
obj.addEventLis tener(evtype, func,false);
}
}catch(e){
//alert the error if you want
}
}
obj will be the cell, evtype will be click and func will be whatever
function you want called when the event occurs. You also need to keep
in mind that the function will have the event for a parameter but from
the event you can find the source of the event. Let me know if this
does not work for you.- Hide quoted text -
- Show quoted text -

Hi Joe,

thanks for your reply.

Where do i have to put that piece of code? Do I have to call that
function somewhere in my code? What do I have to change in my code?

Btw, I will have plenty of cells to assing onClick events and not only
one.
Start by doing the following:
var foo = {
addEvent:functi on(obj, evtype, func){
try{
if(window.attac hEvent){
obj.attachEvent ("on"+evtype , func);
}
if(window.addEv entListener){
obj.addEventLis tener(evtype, func,false);
}
}catch(e){
//ncssmDOM.showEr ror(e);
}
}
}
Several cells wont be a problem. You need to find the table and
iterate through the cells you want to have the event.

for each cell do the following
foo.addEvent(ce ll, "click", bar);

bar will be the name of the function that you will call. If you have
anymore trouble feel free to send me an email.

May 9 '07 #5
On May 9, 4:10 pm, Mister Joe <mrjoefri...@gm ail.comwrote:
On May 9, 10:53 am, joaotsetsemo... @gmail.com wrote:


On May 9, 3:39 pm, Mister Joe <mrjoefri...@gm ail.comwrote:
On May 9, 9:52 am, joaotsetsemo... @gmail.com wrote:
Hello everyone,
I'm having troubles assigning an onclick event to a cell. Im trying
something like
cursorPoint.cel ls[3].style.cursor = "hand";
cursorPoint.cel ls[3].width = "20";
cursorPoint.cel ls[3].onclick = "alert('thi s is a test');"
cursorPoint.cel ls[3].alt = "Select the columns";
cursorPoint.cel ls[3].innerHTML = "&nbsp;"
Everything is just working fine except the onclick. I also tried:
cursorPoint.cel ls[3].click = "alert('thi s is a test');" (without the
"on") but also didnt work.
Any help would be much appreciated
Thanks in advance
Joao
Try this:
addEvent:functi on(obj, evtype, func){
try{
if(window.attac hEvent){
obj.attachEvent ("on"+evtype , func);
}
if(window.addEv entListener){
obj.addEventLis tener(evtype, func,false);
}
}catch(e){
//alert the error if you want
}
}
obj will be the cell, evtype will be click and func will be whatever
function you want called when the event occurs. You also need to keep
in mind that the function will have the event for a parameter but from
the event you can find the source of the event. Let me know if this
does not work for you.- Hide quoted text -
- Show quoted text -
Hi Joe,
thanks for your reply.
Where do i have to put that piece of code? Do I have to call that
function somewhere in my code? What do I have to change in my code?
Btw, I will have plenty of cells to assing onClick events and not only
one.

Start by doing the following:
var foo = {
addEvent:functi on(obj, evtype, func){
try{
if(window.attac hEvent){
obj.attachEvent ("on"+evtype , func);
}
if(window.addEv entListener){
obj.addEventLis tener(evtype, func,false);
}
}catch(e){
//ncssmDOM.showEr ror(e);
}
}}

Several cells wont be a problem. You need to find the table and
iterate through the cells you want to have the event.

for each cell do the following
foo.addEvent(ce ll, "click", bar);

bar will be the name of the function that you will call. If you have
anymore trouble feel free to send me an email.- Hide quoted text -

- Show quoted text -
Joe,

is just worked fine. Exactly what I need. Thanks you very much for
your help

btw ASM, thanks for you reply as well but didn't work. I'm sure the
cursorPoint has the correct id because all the other atributtes are
set correctly and I see it on the browser. Anyway I have my problem
solved. Thanks again.

May 9 '07 #6
ASM
jo************* @gmail.com a écrit :
>
Where do i have to put that piece of code?
nowhere, it is too much complicated only for a simple 'onclick'
What do I have to change in my code?
cursorPoint.onc lick = function() { alert('hello Jao c\'est pas moi'); };
Btw, I will have plenty of cells to assing onClick events and not only
one.
Argghhhh! :-)
function setOnClick(myTa ble, index_of_column ) {
var rangs = document.getEle mentById(myTabl e).rows ||
document.getEle mentById(myTabl e).tbody.rows;
for(var i=0; i<rangs.length ; i++) {
var Cel = rangs[i].cells[index_of_column];
Cel.onclick = function() { alert('got :\n'+this.inner HTML); }
Cel.style.curso r = 'pointer';
Cel.style.backg roundColor = '#ffc';
Cel.onMouseover = function() {this.style.bac kgroundColor='y ellow';};
Cel.onMouseout = function() { this.style.back groundColor = ''; };
}
}
<p><button onclick="setOnC lick('matable', 2);">select col 3</button></p>
<table id="matable" border="1" width="90%" cellspacing="2"
cellpadding="2" align="center">
<tbody>
<tr>
<td>_Row_1_Cell _1_</td>
<td>_Row_1_Cell _2_</td>
<td>_Row_1_Cell _3_</td>
</tr>
<tr>
<td>_Row_2_Cell _1_</td>
<td>_Row_2_Cell _2_</td>
<td>_Row_2_Cell _3_</td>
</tr>
<tr>
<td>_Row_3_Cell _1_</td>
<td>_Row_3_Cell _2_</td>
<td>_Row_3_Cell _3_</td>
</tr>
</tbody></table>
--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
May 9 '07 #7
Mister Joe wrote:
<snip>
addEvent:functi on(obj, evtype, func){
try{
if(window.attac hEvent){
obj.attachEvent ("on"+evtype , func);
}
if(window.addEv entListener){
obj.addEventLis tener(evtype, func,false);
}
}catch(e){
//alert the error if you want
}
}
Are you completely mad? Where is the impaled relationship between an
environment providing either of a global - attachEvent - method or a
global - addEventListene r - method and the - obj - object passed to the
function (presumably a DOM Element) having those methods? What is wrong
a direct test on the properties of the - obj - object, doesn't that have
a precise one-to-one relationship with the object's support for those
methods?

And haven't you understood the role of the - else - keyword in program
flow control? If you encounter an environment that provides both -
attachEvent - and - addEventListene r - (such as some Opera and
IceBrowser versions) you are going to attach the same listener twice,
and have it executed twice for each event. What sort of chaos will that
result in? But even if only - attachEvent - is available (as it is on
IE 5+, the most commonly used/encountered browser) why go on to test for
the existence of - window.addEvent Listener - when you have already found
and used the - attachEvent - method?

Richard.

May 9 '07 #8
ASM
jo************* @gmail.com a écrit :
>
btw ASM, thanks for you reply as well but didn't work.
Huu?

It works !

<p><button
onclick="docume nt.getElementBy Id('goal').oncl ick=function(){ alert('great'); };">
do it</button>
</p>
<table border="1" width="90%" cellspacing="2" >
<tr>
<td>_Row_1_Cell _1_</td>
<td id="goal">_Row_ 1_Cell_2_</td>
<td>_Row_1_Cell _3_</td>
</tr>
<tr>
<td>_Row_2_Cell _1_</td>
<td>_Row_2_Cell _2_</td>
<td>_Row_2_Cell _3_</td>
</tr>
</table>
I'm sure the
cursorPoint has the correct id because all the other atributtes are
set correctly and I see it on the browser.
on WHICH browser ? if it is IE you're sure of anything ! ! !
Anyway I have my problem solved.
Not really if we believe Richard ... :-(

--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
May 9 '07 #9
On May 9, 4:52 pm, ASM <stephanemoriau x.NoAd...@wanad oo.fr.invalid>
wrote:
joaotsetsemo... @gmail.com a écrit :
btw ASM, thanks for you reply as well but didn't work.

Huu?

It works !

<p><button
onclick="docume nt.getElementBy Id('goal').oncl ick=function(){ alert('great'); *};">
do it</button>
</p>
<table border="1" width="90%" cellspacing="2" >
<tr>
<td>_Row_1_Cell _1_</td>
<td id="goal">_Row_ 1_Cell_2_</td>
<td>_Row_1_Cell _3_</td>
</tr>
<tr>
<td>_Row_2_Cell _1_</td>
<td>_Row_2_Cell _2_</td>
<td>_Row_2_Cell _3_</td>
</tr>
</table>
I'm sure the
cursorPoint has the correct id because all the other atributtes are
set correctly and I see it on the browser.

on WHICH browser ? if it is IE you're sure of anything ! ! !
Anyway I have my problem solved.

Not really if we believe Richard ... :-(

--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
I just would like to have something like

cursorPoint.cel ls[3].onclick = "placeCursor()" ;

where place cursor is a function I have defined before. Isn't there a
simple way to do this??

btw, this is for a intranet where the browser has to be IE, so the
browser is not a problem.

Richard, what do you sugest?

May 9 '07 #10

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

Similar topics

4
12555
by: Eric | last post by:
How can I dynamically assign an event to an element? I have tried : (myelement is a text input) document.getElementById('myelement').onKeyUp = "myfnc(param1,param2,param3)"; document.getElementById('myelement') = new Function("myfnc(param1,param2,param3)");
2
11266
by: Barton | last post by:
Hello, I've got a table row with an onClick event that loads page1. Now I do not want to apply this event to one cell of that row because that cell contains already a link to another page. How do I disable the onClick event on that one cell? Code: <table> <tr onClick="window.location=page1.html'> <td></td>
2
7019
by: Andreas Knollmann | last post by:
Hi, I create an object like this: var cell = document.createElement("td"). It doesn't have to be cell. I want this cell to use the onclick event. What doesn't work in the IE as well as with Mozilla is: cell.onclick = "whatever()";
2
18553
by: RobG | last post by:
I am trying to dynamically add an onclick to an element, however I just can't get the syntax right. consider the following function: function doClick (evt,x) { // do things with evt and x } Which is called statically by: <button onclick="doClick(event,this);">Click me</button>
6
9927
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...
0
3142
by: Diane Yocom | last post by:
I'm very new to ASP.Net and probably jumped in a little over my head, but... I'm trying to create a user control that will control navigation through my site. It's sortof like Amazon.com, where there are tabs at the top with "submenu" buttons showing below the selected tab. The data that defines the tabs and submenus is stored in an XML file...
7
2043
by: Dave R | last post by:
Anyone know how to wire up an event handler for controls added to an ASP.NET page at run-time? Of course, at design-time this is easy: just enter the method's name in the event tab of the control's properties. But what if I do... LinkButton lb = new LinkButton(); lb.Text = "Click me now!"; cell.Controls.Add(lb); I want to create a...
2
2820
by: =?Utf-8?B?Uml0YUc=?= | last post by:
I posted this question in the C# discussion group but am posting it here also since ASP is involved. I'm new to C# and need some help regarding an onClick event not firing. I have a data grid that I add a cell to programatically. The cell is a hyperlink and the onClick is set to _doPostBack. In my code I handle the event but when I click...
3
4826
by: Chris | last post by:
I'm guessing the answer is no, but is it possible to assign an event handler to a control using css? For example, I'd like to assign an onclick handler to every <divthat has a class of "foo". Possible? div.foo { onclick: myFunction(this); }
0
7746
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7668
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...
0
8179
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...
0
8036
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...
1
5556
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...
0
5258
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...
0
3699
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2167
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
999
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...

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.