I'm not sure how to achieve the following in javascript, or even if I'm thinking about it correctly. Basically I want to attach a javascript member function to each custom object rendered, so I could have something like this in C#:
public class NumericTextBox : TextBox
{
...
string clientScript = "function isValid() { return isNumericValue(this.value); }";
AttachValidationFunction(clientScript);
}
public class EmailTextBox : TextBox
{
...
string clientScript = "function isValid() { return isEmail(this.value); }";
AttachValidationFunction(clientScript);
}
and then use the following javascript function in the page
function isFormValid() {
var controls = getElementsByClass("validatingControl");
...
if (!controls[i].isValid()) return false;
...
}
obvisouly in pseudo-code, but hopefully that gives the idea of what I need to achieve. Any suggestions?