This is default featured post 1 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured post 2 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured post 3 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured post 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured post 5 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

Kamis, 24 Februari 2011

Textbox Hanya Bisa Diisi Angka dengan JavaScript

Bagaimana ya agar textbox bisa diisi angka saja. Mungkin anda akan bertanya-tanya bagaimana membuatnya. Jadi ketika kita mengetikkan huruf maka tidak akan tampil di dalam textbox tersebut. Namun jika di ketik angka maka textbox akan terisi dengan angka saja.

Pada prinsipnya kita akan mendeteksi keycode dari tombol keyboard yang kita tekan . Jadi ketika kita menekan tombol keyboard , itu dinamakan event keypress , jika dalam dalam code htmlnya adalah onkeypress. Ketika menekan tombol keyboard maka akan membawa yang namanya event. dan itulah yang nanti kita gunakan untuk mendeteksi keycode dari tombol tersebut.

Berikut contoh code untuk membatasi textbox agar bisa diisi angka saja :

<html>
<head>
<title>HOME</title>
<script language="javascript">
function angka(evt)
{
var e = event || evt;
var charCode = e.which || e.keyCode;

if (charCode > 31 || (charCode <> 57))
return false;

return true;

}
</script>
</head>
<body>
<input type="text" name="jumlah" onkeypress="return angka(event);">
</body>
</html>


Selamat mencoba . Semoga bermanfaat .. Terima Kasih