Beranda > Pemrograman > Number Only dan Peringatan Limit (Javascript dan PHP)

Number Only dan Peringatan Limit (Javascript dan PHP)

Skrip dibawah ini berguna untuk membatasi agar user hanya memasukkan angka (number) dan tidak melebihi stok yang ada dalam database.

Source Code :
<script type=”text/javascript”>
function numbersonly(e){
var unicode=e.charCode? e.charCode : e.keyCode
if (unicode!=8){
if (unicode<48||unicode>57)
return false
}
}

function jml(field,g){
if(Number(field.value)>g){
alert(‘Stok tidak mencukupi!’)
field.value =”;
field.focus();
}
}
</script>
<?
$id=$_REQUEST[‘id’];

mysql_connect( “localhost”, “root”, “”)
  or die(“Can’t connect to MySQL!”);
mysql_select_db(“ecomm”);
$sumber = mysql_query(“SELECT * from barang where brgid=’$id'”);
$baris = mysql_fetch_array($sumber);
echo”<form method=\”POST\” name=\”stok\” action=\”beli.php?id=$baris[brgid]\”>”;
echo”Jumlah : $baris[stok]<br> Beli : </b>
<input type=\”text\” name=\”T1\” size=\”5\” onkeypress=\”return numbersonly(event,$baris[stok])\” onkeyup=\”jml(this,$baris[stok])\”>
<input type=\”submit\” value=\”Beli \” name=\”B1\” ></p></form>”;
?>

Iklan
  1. 7 Januari 2015 pukul 2:11 pm

    blog comment

  1. No trackbacks yet.

Tinggalkan Balasan

Please log in using one of these methods to post your comment:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout /  Ubah )

Foto Google+

You are commenting using your Google+ account. Logout /  Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout /  Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout /  Ubah )

w

Connecting to %s

%d blogger menyukai ini: