472,989 Members | 3,007 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,989 software developers and data experts.

cell.onclick="..." not work?

Hi, this is the code, and new row and new cell generated ok, but why
the
onclick and onmouseover doen't work?
Thank you in advance!

<html>
<head>
<script language="javascript">
function inserttable()
{
alert("running");
var oRow = testtable.insertRow();
var cell = oRow.insertCell();
cell.innerHTML = "hello";
cell.onclick="javascript:alert('hello');";
cell.onmouseover = "javascript:alert('mouseOver');"
return;
}
</script>
</head>
<body>
<table>
<tr>
<td><input type="button" name="Test" value="Click"
onclick="javascript:inserttable();"></td>
</tr>
<tbody id="testtable">
</tbody>
</table>
</body>
</html>

Feb 13 '06 #1
2 8009
Peter wrote:
cell.onclick="javascript:alert('hello');";


Read about such `javascript:' nonsense in this newsgroup's FAQ.
Furthermore, the value of the (proprietary) `onclick' property
of DOM element objects has to be a Function object reference,
`null' or `undefined'. Since you want the UA do something on
event:

cell.onclick = function()
{
alert('hello');
};

BTW, this is definitely a FAQ here. Please do research on previous
articles before you post, it is both very annoying and tiresome to
answer the same questions all over again. It is called _news_group
for a reason.

BTW 2: Your HTML code is not Valid markup.

<URL:http://validator.w3.org/>
PointedEars
Feb 13 '06 #2
Peter wrote:
Hi, this is the code, and new row and new cell generated ok, but why
the
onclick and onmouseover doen't work?
Because there are errors in the script.

Thank you in advance!

<html>
<head>
<script language="javascript">
The language attribute is deprecated, type is required:

<script type="text/javascript">

function inserttable()
{
alert("running");
var oRow = testtable.insertRow();
var cell = oRow.insertCell();
cell.innerHTML = "hello";
cell.onclick="javascript:alert('hello');";
'javascript:' is typically used as a pseudo-protocol in the value of a
href attribute of an A element, e.g.:

<a href="javascript:someFn();" ... >

However usually a real href should be supplied and an onclick handler
used for the script:

<a href="realPage" onclick="someFn();return false;" ... >
When setting the value of an onclick property using script, you can't
just plug in arbitrary code, use either an anonymous function:

cell.onclick = function(){alert('hello');}
or define the function elsewhere and pass a reference:

function sayHello()
{
alert('hello');
}
function inserttable()
{
...
cell.onclick = sayHello; // Note lack of '()'
...
}

cell.onmouseover = "javascript:alert('mouseOver');"

Same for onmouseover.

return;
}
</script>
</head>
<body>
<table>
<tr>
<td><input type="button" name="Test" value="Click"
onclick="javascript:inserttable();"></td>
Here 'javascript:' should be omitted, leaving just the function call:

<td ... onclick="inserttable();"></td>

And it is normal to give a button a more meaningful label than 'click',
but I guess this is just an example.

</tr>
<tbody id="testtable">
A tbody element without rows is invalid HTML ... but not too many user
agents will quibble over that.

</tbody>
</table>
</body>
</html>


--
Rob
Feb 13 '06 #3

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

Similar topics

10
by: Eric-Sebastien Lachance | last post by:
Hey there, I decided to just create a 100% height and width div that filled the space over a background header image, and add an onclick event to redirect to the my index... Doesn't seem to work...
5
by: johnsuth | last post by:
I want to produce a trivial demonstration of dynamic modification. I thought that pressing a button might change its color. I studied O'Reillys books and successfully created the button with a...
13
by: alvin.yk | last post by:
Hi, Normally, a piece of code such as <a href="http://www.yahoo.com" onclick="alert('hello');return false;">link</a> will stop the browser from actually going to href's destination....
11
by: jesdynf | last post by:
I'm having trouble applying a stylesheet to content I'm generating after the fact. Here's the sample code: <html> <head> <title>CSS/DOM Problem Example</title> <style type="text/css">...
1
by: grantmx | last post by:
Hey guys - We am having problems with the following code in our form: <tr><td></td><td align=right><input type="image" name="_ctl25:btnSaveLarge" onclick="if (typeof(Page_ClientValidate) ==...
4
by: John Nagle | last post by:
I'm printing out each entry in "gc.garbage" after a garbage collection in DEBUG_LEAK mode, and I'm seeing many entries like <cell at 0x00F7C170: function object at 0x00FDD6B0> That's the...
2
by: ejrfigueiredo | last post by:
Hi, Is there a way to get a script function to save a page without the execCommand (which works on IE but doesn't on Firefox). Below there's the code I'm using, I took it from a template page...
5
by: dangt85 | last post by:
Hello, I have the following page: ... <style type="text/css"> body { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; }
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

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.