I have file with jspx extension i write javascript like
function isNumber(inputId){
var value = document.getElementById('mainForm:'+ inputId).value;
var s = value.length;
while(s >= 0){
var c = value.charAt(s);
if(c > "9"){
alert("Value must be digit");
document.getElementById('mainForm:'+ inputId).value = "";
document.getElementById('mainForm:'+ inputId).focus();
return false;
}
s --;
}
return true;
}
that work perfect but when i check if condition like if(c > "9" || c < "0") it will gives error like
com.sun.facelets.FaceletException: Error Parsing /WEB-INF/includes/templates/cc-classic-template.jspx: Error Traced[line: 386] The content of elements must consist of well-formed character data or markup.
After long observation i found that <(less than) sign will create problem. Is JSF not support < sign ?
Enclose your Javascript in CDATA Sections:
<script language="javascript" type="text/javascript">
/* <![CDATA[ */
function isNumber(inputId){
var value = document.getElementById('mainForm:'+ inputId).value;
var s = value.length;
while(s >= 0){
var c = value.charAt(s);
if(c > "9"){
alert("Value must be digit");
document.getElementById('mainForm:'+ inputId).value = "";
document.getElementById('mainForm:'+ inputId).focus();
return false;
}
s --;
}
return true;
}
//Code containing "<" also comes in this section
/* ]]> */
</script>