0

Could someone explain in the most simplistic terms possible why this doesn't work:

var cell00501=row005.insertCell(-1);
  cell00501.align="center";
  cell00501.width="8%";
  cell00501.onclick="RadioClicked(0)";
  cell00501.innerHTML="<IMG SRC='RadioOn.jpg' BORDER='0' NAME='Spangle0'>";

By doesn't work I mean the onclick event doesn't result in the RadioClicked() function being called. I have come up with the following workaround:

var cell00503=row005.insertCell(-1);
  cell00503.align="center";
  cell00503.width="8%";
  cell00503.innerHTML="<DIV onclick='RadioClicked(1)'><IMG SRC='RadioOff.jpg' BORDER='0' NAME='Spangle1'></DIV>"

However I would like to understand where I am going wrong.

Many thanks.

2
Contributors
2
Replies
4
Views
5 Years
Discussion Span
Last Post by BAEdwards
0

Hi,
I think these examles explain you way "onclick" not works in your script.
This works:

element.onclick = function_name;

Not works:

element.onclick = function_name(argument);

Not works:

element.onclick = "function_name(argument)";

Works:

element.onclick = function() { function_name(argument); };

Edited by MarPlo

0

Many thanks for your reply.

So the below is the correct syntax for calling a function when passing a value/argument into it:

element.onclick = function() { function_name(argument); };

but it doesn't seem a very consice approach. If

element.onclick = function_name;

works for calling a function that doesn't require anything to be passed into it why doesn't:

element.onclick = "function_name(argument)";

work when the function does require a value/argument to be passed into it?

It all seems very illogical.

Just out of interest would

cell00503.innerHTML="<DIV onclick='RadioClicked(1)'><IMG SRC='RadioOff.jpg' BORDER='0' NAME='Spangle1'></DIV>"

cause problems with some browsers? Would it be considered an acceptable piece of code?

Many thanks.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.