0

I m creating a web application using object oriented javascript.I m having one class is having a function. var Section = function () { this.Test=function(){} }.

From <a href="#" /> i want to call the function Test().

<a href="#" onclick="new Section() Test()"/>.

I m trying like this it was not working.

Is there any other option is there to call a function from control? Please suggest me.

Ramasamy Kanna
  • 794
  • 3
  • 11
  • 32

2 Answers2

2

If you have a function or a variable inside an Object you have to use a . to access it. So in your case it should be :

var Section = function() {

    this.Test = function() {
        // Do something
    };
}  

And in your HTML:

<a href="#" onclick="new Section().Test()"/>
putvande
  • 15,068
  • 3
  • 34
  • 50
1

You can call the javascript inside the href or inside the onClick attributes, like so:

<a href="javascript:var section = new Section(); section.Test();">

or

<a href="#" onClick="var section = new Section(); section.Test();">

Hope it helps, good luck!

Milanzor
  • 1,920
  • 14
  • 22