7079
12-14-2006, 05:02 PM
I would like to take the following function and possibly pass it a parameter so that it would stand alone as a separate function.
function tmt_validatorInit(){
var formNodes = document.getElementsByTagName("form");
for(var i=0; i<formNodes.length; i++){
if(formNodes[i].getAttribute("tmt:validate") == "true"){
// Attach a validator object to each form that requires it
formNodes[i].tmt_validator = new tmt_formValidator(formNodes[i]);
// Set the form node's onsubmit event
// We use a gigantic hack to preserve exiting calls attached to the onsubmit event (most likely validation routines)
if(typeof formNodes[i].onsubmit != "function"){
formNodes[i].onsubmit = function(){
return tmt_validateForm(this);
}
}
else{
// Store a reference to the old function
formNodes[i].tmt_oldSubmit = formNodes[i].onsubmit;
formNodes[i].onsubmit = function(){
// If the existing function return true, send the form
if(this.tmt_oldSubmit()){
return tmt_validateForm(this);
}
return false;
}
}
}
}
}
I want to do this so that I can do the following upon adding dynamic rows:
tmt_validatorInit(num);
num is the variable that gets incremented as you add a row. So it will initialize a new tmt_validator for every dynamic row. I just don't know enough javascript to do it myself and I was hoping that a Javascript Guru could help with this problem.
Please help me resolve this issue as it is been a problem for several days.
function tmt_validatorInit(){
var formNodes = document.getElementsByTagName("form");
for(var i=0; i<formNodes.length; i++){
if(formNodes[i].getAttribute("tmt:validate") == "true"){
// Attach a validator object to each form that requires it
formNodes[i].tmt_validator = new tmt_formValidator(formNodes[i]);
// Set the form node's onsubmit event
// We use a gigantic hack to preserve exiting calls attached to the onsubmit event (most likely validation routines)
if(typeof formNodes[i].onsubmit != "function"){
formNodes[i].onsubmit = function(){
return tmt_validateForm(this);
}
}
else{
// Store a reference to the old function
formNodes[i].tmt_oldSubmit = formNodes[i].onsubmit;
formNodes[i].onsubmit = function(){
// If the existing function return true, send the form
if(this.tmt_oldSubmit()){
return tmt_validateForm(this);
}
return false;
}
}
}
}
}
I want to do this so that I can do the following upon adding dynamic rows:
tmt_validatorInit(num);
num is the variable that gets incremented as you add a row. So it will initialize a new tmt_validator for every dynamic row. I just don't know enough javascript to do it myself and I was hoping that a Javascript Guru could help with this problem.
Please help me resolve this issue as it is been a problem for several days.