I have tried adding events using the jQuery Attr function before and it doesn't seem to work.
I think the reason must be that the client has to add the event in a particular way or the fact that it's a function gets lost.
Try:
btnSave.onclick = validateEmail;
or
btnSave.onclick = function(){
validateEmail();
}
If that doesn't work, let me know and I'll look further ^_^
Andy
UPDATE:
Via Jquery this is much easier:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.js"></script>
<script type="text/javascript">
;
function validateEmail() {
var emailTxt = $("input[id='txtUEmail']")
var emailID = $(emailTxt).val();
atpos = emailID.indexOf("@");
dotpos = emailID.lastIndexOf(".");
if (atpos < 1 || (dotpos - atpos < 2)) {
alert("Please enter correct email ID")
$(emailTxt).focus();
return false;
}
return (true);
}
$(function(){
var saveButton = $("button[id='btnSave']");
$(saveButton).click(function(){
validateEmail();
});
});
</script>
Your next step is to debug the javascript. Chrome has a great one build it (just hit F12). IE has one but it's not my fav. Firefox requires the FireBug extension install, but it's pretty good.
Hope that helps ^_^
Andy