Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
in a fom validation system i want to combine all form validation js file into a common js file so corresponding html file text file, password field id,text area id's sent inside onclick function
Posted
Comments
Afzaal Ahmad Zeeshan 26-Mar-15 22:50pm    
You need to have all of this data on the web page when you handle the button event. Do you have all of the code at one place?
Santosh K. Tripathi 27-Mar-15 0:04am    
Hi, Could you explain bit more your requirement?

for each of the fields or elements you want to validate make variables globally or in a class/object e.g

JavaScript
var passfield = document.getElementById('id');


then check the values/content.
 
Share this answer
 
This event's handler accepts the method arguments it accepts, MouseEvent object, nothing else:
https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XUL/Attribute/onclick[^],
https://developer.mozilla.org/en-US/docs/Web/Events/click[^],
https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent[^].

So, you can pass required id information though outside context, such as
JavaScript
var idSet = // some object representing id set,
            // such as array

//...

myElement.onclick = function(eventInfo) {
   var x = eventInfo.screenX;
   var y = eventInfo.screenY;
   doSomething(x, y, idSet);
}


Alternatively, you can calculate the elements by id inside the handler, but it will be done on each event, and make not much more sense, because it's better to reuse the element references or the values of id attributes:

JavaScript
myElement.onclick = function(eventInfo) {
   var x = eventInfo.screenX;
   var y = eventInfo.screenY;
   var myTextArea = document.getElementById("text");
   var myInput = document.getElementById("input");
   doSomething(x, y, myTextArea, myInput); // whatever
}


—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900