rules for onclick?

  • Thread starter murrayatuptowngallery
  • Start date
M

murrayatuptowngallery

I would like to combine a snippet that captures mouse position with
onclick to insert one axis of the mouse position into a variable for
form use.

I have the mouse position capture part ok.

Tutorial examples of onclick only explore what the author thinks are
typical uses of onclick.

So I guess I need to study the rules (or ask) for onclick...

What I envision, conceptually (what follows is not correct language-
wise - just look at for concept for now, please).


<A HREF="something"
onClick="VAR A=mouseX)";</A>

If mouse is clicked, I want one of the mouse position variables
defined by a separate mouse capure script insered into another
variable.

Can this be done, and is the HTML or JavaScript standard entry for
onclick the place to learn the rules for this, or is it a
combinational function that I will no find documentation on?

Thank you

Murray
 
R

RobG

<button onclick="var a=event.clientX">Click me to set the value of
variable a</button>

I think you need to be a little careful about that. In some browsers,
the result might be a global variable (window.a) but in others a might
be local to the anonymous function assigned to the onclick handler.

It is probably OK to prototype stuff using script inside an HTML
attribute value, but for robustness they should be restricted to
function calls or simple statements like "return false".
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top