Berikut ini script javascript untuk membaut format angka pada inputan form text :
<script type="text/javascript">
function formatangka(objek)
{
a = objek.value;
b = a.replace(/[^\d]/g,"");
c = "";
panjang = b.length;
j = 0;
for (i = panjang; i > 0; i--)
{
j = j + 1;
if (((j % 3) == 1) && (j != 1))
{
c = b.substr(i-1,1) + "," + c;
} else {
c = b.substr(i-1,1) + c;
}
}
objek.value = c;
}
</script>
function formatangka(objek)
{
a = objek.value;
b = a.replace(/[^\d]/g,"");
c = "";
panjang = b.length;
j = 0;
for (i = panjang; i > 0; i--)
{
j = j + 1;
if (((j % 3) == 1) && (j != 1))
{
c = b.substr(i-1,1) + "," + c;
} else {
c = b.substr(i-1,1) + c;
}
}
objek.value = c;
}
</script>
kemudian pada Form HTML nya :
<input type="text" name="gp_price" onkeyup="formatangka(this)" value="">
No comments:
Post a Comment