I am trying to create a function in jQuery based on the data attr.
<input type="text" name="name" id="name" data-validate="validatename" />
$("#name").blur(function(){
var validate = $(this).attr("data-validate");
var newvalidate = validate+"()";
newvalidate;
});
function validatename(){
alert("success");
}
Debugging gives the value of newvalidate as validatename() but the function doesn't run. How can i make this work?
window[validate]()instead of introducingnewValidate.validate+"()";to do, because I doubt it's what you are thinking it is (it's just a string).