Object Expected error using TD element

S

snowburnt

hi,

I'm trying to script a simple class change and it isn't working. when
I script it into the event handler of the tag it works fine, however,
I want more to happen with it in the long run than just changing the
class of the td element.

this is what I have in the script tags:

function.doMouseOver(elm)
{
elm.className='MouseOver';
{

I even tried passing nothing to the function and have it display an
alert window to test and it wouldn't even do that.

here's the tag and the event handler:

<td id="ticket5" class="unClicked" onMouseOver="doMouseOver(this);"
onMouseOut="this.className='unClicked';"
onClick="this.className='Clicked';">

when I used "this.className='MouseOver'" in the event handler, it
worked. whenever I try to call any function it gives object expected.

I also tried not passing anything and using "this" in the function
instead of the reference.

what am I doing wrong?

let me know if you need anymore information.
 
D

David L. Goldberg

hi,

I'm trying to script a simple class change and it isn't working. when
I script it into the event handler of the tag it works fine, however,
I want more to happen with it in the long run than just changing the
class of the td element.

this is what I have in the script tags:

function.doMouseOver(elm)
{
elm.className='MouseOver';
{

I even tried passing nothing to the function and have it display an
alert window to test and it wouldn't even do that.

here's the tag and the event handler:

<td id="ticket5" class="unClicked" onMouseOver="doMouseOver(this);"
onMouseOut="this.className='unClicked';"
onClick="this.className='Clicked';">

when I used "this.className='MouseOver'" in the event handler, it
worked. whenever I try to call any function it gives object expected.

I also tried not passing anything and using "this" in the function
instead of the reference.

what am I doing wrong?

let me know if you need anymore information.

that second '{' (line 4 of the function) isn't in the code is it? :)
 
B

Bart Van der Donck

snowburnt said:
I'm trying to script a simple class change and it isn't
working. when I script it into the event handler of the
tag it works fine, however, I want more to happen with
it in the long run than just changing the class of the
td element.

this is what I have in the script tags:

function.doMouseOver(elm)
{
elm.className='MouseOver';
{

I even tried passing nothing to the function and have
it display an alert window to test and it wouldn't even
do that.

here's the tag and the event handler:

<td id="ticket5" class="unClicked"
onMouseOver="doMouseOver(this);"
onMouseOut="this.className='unClicked';"
onClick="this.className='Clicked';">

Two syntax errors:
- the last '{' should be a '}'
- 'function.doMouseOver' should be 'function doMouseOver'

One bad habit:
- 'MouseOver' sounds like a property name rather than a class

So:

<html>
<head>
<title>My web page</title>
<style type="text/css">
.green { background-color:green }
</style>
<script type="text/javascript">
function doMouseOver(elm) {
elm.className='green'
}
</script>
</head>
<body>
<table border="1">
<tr>
<td onClick="doMouseOver(this);">click me</td>
</tr>
</table>
</body>
</html>

Hope this helps,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top