OnClick

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sumaira Maqsood Ali

    #1

    OnClick

    hi,
    I wanted to know if OnClick can be used outside forms also?
    like can plain text have the OnClick event handler associated with it?
    thanks
    Sumaira

  • Lasse Reichstein Nielsen

    #2
    Re: OnClick

    Sumaira Maqsood Ali <sali@purdue.ed u> writes:
    [color=blue]
    > I wanted to know if OnClick can be used outside forms also?
    > like can plain text have the OnClick event handler associated with it?[/color]

    That depends on the browser.
    I tested this code:
    <p onclick="alert( 'foo');">text</p>
    in my browsers, and it works in IE6, Mozilla Firebird 0.6 and Opera 6+.
    It didn't work in Netscape 4.

    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • David Dorward

      #3
      Re: OnClick

      Sumaira Maqsood Ali wrote:
      [color=blue]
      > hi,
      > I wanted to know if OnClick can be used outside forms also?
      > like can plain text have the OnClick event handler associated with it?[/color]

      http://www.w3.org/TR/html4/interact/....html#h-18.2.3

      onclick = script [CT]
      The onclick event occurs when the pointing device button is clicked over
      an element. This attribute may be used with most elements.

      --
      David Dorward http://david.us-lot.org/
      Which is stupider: Pop-up ads claiming they'll stop spam, or spam claiming
      it'll stop pop-up ads? -- Dork Tower

      Comment

      • Lee

        #4
        Re: OnClick

        Lasse said:[color=blue]
        >
        >Sumaira Maqsood Ali <sali@purdue.ed u> writes:
        >[color=green]
        >> I wanted to know if OnClick can be used outside forms also?
        >> like can plain text have the OnClick event handler associated with it?[/color]
        >
        >That depends on the browser.
        >I tested this code:
        > <p onclick="alert( 'foo');">text</p>
        >in my browsers, and it works in IE6, Mozilla Firebird 0.6 and Opera 6+.
        >It didn't work in Netscape 4.[/color]

        In Netscape 4, you can enclose the text in a Link, with text-decoration:none .

        <head>
        <style type="text/css">
        A {text-decoration:none }
        </style>
        </head>
        <body>
        Click <a href="about: Me" onclick="alert( 'hello');return false">Me</a>.
        </body>

        Note that this example behaves badly if Javascript isn't enabled.

        Comment

        • Lasse Reichstein Nielsen

          #5
          Re: OnClick

          Sumaira Maqsood Ali <sali@purdue.ed u> writes:
          [color=blue]
          > It works if I do onClick='alert( ....)' but it doesnt work if i do
          > onClick='somefu nction(....)' why is that so?[/color]

          That must be because "somefuncti on" doesn't exist or doesn't work,
          or there is a typo in the call to it.
          /L
          --
          Lasse Reichstein Nielsen - lrn@hotpop.com
          Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
          'Faith without judgement merely degrades the spirit divine.'

          Comment

          • kaeli

            #6
            Re: OnClick

            In article <3F2821F2.60603 02@purdue.edu>, sali@purdue.edu enlightened us
            with...[color=blue]
            > It works if I do onClick='alert( ....)' but it doesnt work if i do
            > onClick='somefu nction(....)' why is that so?
            > thanks
            > sumaira
            >[/color]

            You probably have an error in the function or you spelled it differently
            - capitalization matters.

            -------------------------------------------------
            ~kaeli~
            Black holes were created when God divided by 0.
            Not one shred of evidence supports the notion
            that life is serious.


            -------------------------------------------------

            Comment

            Working...