Javascript In Jsf/icefaces
I have file with jspx extension i write javascript like function isNumber(inputId){ var value = document.getElementById('mainForm:'+ inputId).value; var
Solution 1:
Enclose your Javascript in CDATA Sections:
<scriptlanguage="javascript"type="text/javascript">/* <![CDATA[ */functionisNumber(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();
returnfalse;
}
s --;
}
returntrue;
}
//Code containing "<" also comes in this section/* ]]> */</script>
Solution 2:
As explained by Matt Handy, you could not use the <
or >
sign in your JSPX, as this is a XML format. You have three solutions regarding your problem:
- Escape by using
<
or>
. - Use
<![CDATA[ ... ]]>
to hold your JavaScript code in your page. - Set your JavaScript code in a separate
.js
file, and load it in your JSPX page.
Solution 3:
Besides the escaping and CDATA answers:
If you want to check if a value is a number, there is a javascript built-in function for that: isNaN
Here is an example:
if (isNaN(document.getElementById('mainForm:'+ inputId).value))
{
alert("Please enter digits");
document.getElementById(obj).focus();
document.getElementById(obj).select();
returnfalse;
}
Post a Comment for "Javascript In Jsf/icefaces"