Sunday, January 25, 2009

Change dot "." to Comma "," with javascript

Here is the syntax to change your dot to comma.
Very handy because your hand stays in the nummeric area of your keyboard.

<html>
<head>

<script type="text/javascript">
function DotToComma(that) {
if (that.value.indexOf(".") >= 0) {
that.value
= that.value.replace(".",",");
}
}
</script>

</head>
<body>
<input type="text" name="txt" onkeyup="DotToComma(this);">
</body>
</html>


On a .ASPX page you would have something inside like this:

<asp:textbox id="TextBox1" runat="server" text="Sample Text"
onkeyup
="DotToComma(this);" />

1 comment:

Lieve said...

I have been looking all over for a simple solution that works. thx