0

I have a jsp where in I include many javascript files. I registered a method name "validate()" onclick of a button.

I wrote this method definition in a javascript file(validator1.js) which is included in the jsp. Now when the onclick event of the button is triggered, a validate method in a different file ("globalValidator1.js") is getting called.

For now I have changed the onclick method name and the definition of my method,

But is there a way, in which I can ensure that my method gets called? Any inputs will be appreciated.

Sashi Kant
  • 13,277
  • 9
  • 44
  • 71
  • this might help you http://stackoverflow.com/questions/6885404/javascript-override-methods – Gautam Apr 17 '14 at 13:05
  • @Gautam: Thanks for the reference, but I am not using a OOP, its a normal javascript method – Sashi Kant Apr 17 '14 at 13:07
  • You will have to disambiguate the two functions, either by removing one of them from the global scope and calling it differently, changing their names as you have done, or wrapping the code in each validator file into its own JavaScript "class" (or module, namespace, or other scoping mechanism) and using each appropriately. – Cᴏʀʏ Apr 17 '14 at 13:37

1 Answers1

1

u may try like this:

validator1.js

window.ur = {
    validate : function () {
      // ur validation logic
    };
};

ur.jsp

ur.validate();

globalValidator1.js //u may skip this part if u r not allowed to touch this one

window.glb = {
    validate : function () {
      // others validation logic
    };
};
  • Thanks for your response, can you help me out. Is there a rule for which a browser decides which method to call from two methods having same signature? – Sashi Kant Apr 17 '14 at 13:09