Click to See Complete Forum and Search --> : Valid Javascript to get working in xslt


ISMAILC
01-06-2009, 09:52 AM
Hi,

I found this code that allows anly numeric char, the problem i have is that the xslt file does not like the script:


<SCRIPT TYPE='text/javascript'>
function IsNumeric(sText)
{
var ValidChars = "0123456789.";
var IsNumber=true;
var Char;


for (i = 0; i < sText.length && IsNumber == true; i++)
{
Char = sText.charAt(i);
if (ValidChars.indexOf(Char) == -1)
{
IsNumber = false;
}
}
return IsNumber;

}

</SCRIPT>


Please Assist!

Charles
01-06-2009, 10:08 AM
The better version of that would be:function isNumeric (s) {
return /^\d+$/.test (s);
}But as you have discovered, XSL doesn't support JavaScript. It can be extended and if you are transforming to HTML that HTML can contain JavaScript. What exactly, and in great detail, are you up to?

Scriptage
01-06-2009, 10:26 AM
You need to correctly wrap the code in CDATA tags otherwise the XSLT processor will try to interpret it:


<script type="text/javascript">
/* <![CDATA[ */
content of your Javascript goes here
/* ]]> */
</script>


Alternatively have the script in an external file and link to it.

ISMAILC
01-07-2009, 03:00 AM
Hi, Thank You All.

I have dev toool that uses asp + xslt page.
On the dev tool I have objects, text box with poperties & events i can use.

The problem i have is that I only want a numeric value in a textbox of datatype text. Don't want to change it to numeric as it rounds/trims the value when wanting to do a calulcation.

So in the xslt file i want to add a javascript function that i can use on the onkeyevent of the textbox not to allow numeric characters.

Still struggling though!

The function between the <![CDATA[ is like it is filtered out (font light grey) and can't use the function.

<SCRIPT TYPE='text/javascript'>
<![CDATA[
function IsNumeric(sText)
{
var ValidChars = "0123456789.";
var IsNumber=true;
var Char;

for (i = 0; i < sText.length && IsNumber == true; i++)
{
Char = sText.charAt(i);
if (ValidChars.indexOf(Char) == -1)
{
IsNumber = false;
}
}
return IsNumber;

}
]]>
</SCRIPT>



Regards