Hi. Everyone
I’m using an xslt stylesheet to transform my xml document to an html doc. In addition I need to include some pieces of JavaScript for validation purpose. JavaScript code needed to be placed between /* <![CDATA[*/ and /*]]>*/ in order to avoid parsing issue. So far so good, but what has derived me crazy is that why at run time the xslt processor weed out the <![DATA and ]]> from the target html document and just keep /**/. This is obvious by browsing the source code in the browser. And what surprise me is that the special JavaScript characters like ( < , > , &&) were converted into (< , &&
. As a result JavaScript code was frozen and the validation was escaped.
Here is my code
<html>
<head>
<script language="JavaScript">
/* <![CDATA[*/
function isvalid(){
var myelements=document.getElementsByTagName("input");
var counter=myelements.length
for (var i=0;i< counter;i++){
var para=myelements.value;
if (myelements.getAttribute("idnull")=='False'){
if (isEmpty(para)){
alert("please fill in the box !"+myelements.name)
return false
}
}
} //for
return true;
} //isvalid
function isEmpty(para){
var fieldname=para;
if (fieldname== null || fieldname == ""){
return true;
}
return false;
} // is Empty
/* ]]> */
</script>
</head>
<body>
<h4>
<i> All fields are required. </i>
</h4>
<form name="form1" method="GET" onSubmit="return isvalid()" >
id_card<input type="text" name="id_card" idnull="False"/>
<br/>
address<input type="text" name="address" idnull="False"/>
<br/>
d_of_birth<input type="text" name="d_of_birth" idnull="False"/>
<br/>
<input type="reset" value="Clear All Fields"/>
<input type="submit" VALUE="SUBMIT"/>
</form>
</body>
</html>
any clue?
Many thanks in advance
I’m using an xslt stylesheet to transform my xml document to an html doc. In addition I need to include some pieces of JavaScript for validation purpose. JavaScript code needed to be placed between /* <![CDATA[*/ and /*]]>*/ in order to avoid parsing issue. So far so good, but what has derived me crazy is that why at run time the xslt processor weed out the <![DATA and ]]> from the target html document and just keep /**/. This is obvious by browsing the source code in the browser. And what surprise me is that the special JavaScript characters like ( < , > , &&) were converted into (< , &&
Here is my code
<html>
<head>
<script language="JavaScript">
/* <![CDATA[*/
function isvalid(){
var myelements=document.getElementsByTagName("input");
var counter=myelements.length
for (var i=0;i< counter;i++){
var para=myelements.value;
if (myelements.getAttribute("idnull")=='False'){
if (isEmpty(para)){
alert("please fill in the box !"+myelements.name)
return false
}
}
} //for
return true;
} //isvalid
function isEmpty(para){
var fieldname=para;
if (fieldname== null || fieldname == ""){
return true;
}
return false;
} // is Empty
/* ]]> */
</script>
</head>
<body>
<h4>
<i> All fields are required. </i>
</h4>
<form name="form1" method="GET" onSubmit="return isvalid()" >
id_card<input type="text" name="id_card" idnull="False"/>
<br/>
address<input type="text" name="address" idnull="False"/>
<br/>
d_of_birth<input type="text" name="d_of_birth" idnull="False"/>
<br/>
<input type="reset" value="Clear All Fields"/>
<input type="submit" VALUE="SUBMIT"/>
</form>
</body>
</html>
any clue?
Many thanks in advance