I have a neat Javascript function that checks the validity of a bound field. However, I want to place an ELSE {} in the line to send an alert() function call and display an error.
This is what works for me...
onClick='<%# "if(chkMobile(\"" + Eval("pssPhone").ToString() + "\")) { highlightRow(this); }" %>'
This does not work for me ...
onClick='<%# "if(chkMobile(\"" + Eval("pssPhone").ToString() + "\")) { highlightRow(this); } else { alert('Invalid mobile phone number'); }" %>'
I've tried to escape the single quotes with \'
, \\\'
, \'''
, and even '
on its own. I always get badly formed errors.
The '
does not work either, but at least I don't get any errors. In fact with the '
the highlightRow() doesn't fire which is worse!
I've also tried "
with no luck.
Thank you for your time.
[SOLVED] I took a punt and decided to inject double-quotes and it works like a charm!
onClick='<%# "if(chkMobile(\"" + Eval("pssPhone").ToString() + "\")) { highlightRow(this); } else { alert(\"" + "Invalid mobile phone number" + "\"); }" %>'