javascript - HTML Input element (field.validate) is always undefined -
i'm having 2 text boxes defined onblur
event. on pressing tab, whenever onblur
event called field.validate
undefined
.
at same time, when i'm trying print field.name
or field.getattribute("validate")
return proper value.
<input width="100%" type="text" name="nv_active" id="nv_active" value="5" onblur="return dovalidate(this);" validate=" return validatevaluefield(document.getelementbyid('nv_active'), 'active' );"> <input width="100%" type="text" name="nv_throttled" id="nv_throttled" value="15" onblur="return dovalidate(this);" validate=" return validatevaluefield(document.getelementbyid('nv_throttled'), 'throttled' );"> function dovalidate(field) { console.log("field.validate- " + field.validate); //always printing undefined console.log("getattr- " + field.getattribute("validate")); //return validatevaluefield(document.getelementbyid('nv_active'), 'active' ); if (field.validate != null) { var f = new function(field.validate); return f(); } return true; } function validatevaluefield(field, displayname) { if ((field.name == 'nv_activepollinginterval') || (field.name == 'nv_throttledpollinginterval') ) { //some validation code , error alert message } }
i not able figure out why it's undefined.
using field.getattribute('attr')
retrieve value of dom element's attribute.
using field.attr
retrieve property attr
of dom element , not same thing.
i recommend check question: getattribute() versus element object properties? , accepted answer, should you.
Comments
Post a Comment