| |
Forum PHP IndonesiaDapatkan pertolongan pertama pada kebingungan PHP dan sekitarnya |
|
|
|
|
|
| |
|
|
All times are GMT + 7 Hours
|
|
Javascript error
 |
Mon Feb 08, 2010 10:31 |
 |
Author |
Message |
Harpan Anak Baru

Joined: 08 Feb 2010 Posts: 1
|
| Post subject: Javascript error |
|
|
saya pemula.. tapi saya mendapatkan soal,, terus terang saya belum ada gambaran tentang javascript.
berikut html sederhana yg saya buat
<html>
<head>
</head>
<body>
<h2>Perhitungan </h2>
<form name=“form_coba”>
Kode barang : <input type=“text” name=“kode_barang”><br>
Harga beli : Rp <input type=“text” name=“harga_beli”><br>
<input type=“button” value=“Hitung” onclick=“prosesHitung()”>
</form>
</body>
</html>
nah masalahnya saya binggung dalam menuangkan javascript dalam html diatas :
Masalah :
1. Kode barang diinputkan dengan format “A-9999”, dimana :
a. huruf “A” diganti dengan “I” untuk barang impor atau “L” untuk barang lokal.
b. angka “9999” merupakan nomor urut biasa.
2. Setiap barang dikenai pajak sebesar 10% untuk barang lokal dan 20% untuk barang impor. Pajak dihitung dari harga belinya.
3. Setiap barang diambil keuntungan/laba sebesar 15% dari harga belinya.
Contoh perhitungan :
• Jika diinputkan kode barang “L-1234” dan harga beli Rp 10000, maka :
harga beli = 10000
laba = 15% x 10000 = 1500
pajak = 10% x 10000 = 1000
harga jual = 12500
• Jika diinputkan kode barang “L-1234” dan harga beli Rp 10000, maka :
harga beli = 10000
laba = 15% x 10000 = 1500
pajak = 20% x 10000 = 2000
harga jual = 13500
Output program :
Tampilkan harga jual barang tersebut dalam bentuk alert.
terima kasih..salam dari kalimantan[/b] |
|
| |
|
|
 |
Tue Feb 09, 2010 14:54 |
 |
Author |
Message |
vortexgin PHP Programmer

Joined: 28 Jan 2009 Posts: 113 Location: Jakarta
|
| Post subject: |
|
|
coba ini :
| Code: | <?php <html>
<head>
<script language="javascript">
function validateCode(code){
if(((code.value.substring(0,2) == 'I-') || (code.value.substring(0,2) == 'L-')) && ((code.value.length == 6))){
return true;
}else{
return false;
}
}
function isLocal(code){
if(code.value.substring(0,2) == 'L-'){
return true;
}else{
return false;
}
}
function isImport(code){
if(code.value.substring(0,2) == 'I-'){
return true;
}else{
return false;
}
}
function Calculate(){
var code = document.getElementById('kode_barang');
var price = document.getElementById('harga_beli');
var taxRate;
var profitRate = 15/100;
var tax, profit, total;
if(! validateCode(code)){
alert('Undefined Code !!!');
}
if(isLocal(code)){
taxRate = 10/100;
}else{
taxRate = 20/100;
}
tax = price.value * taxRate;
profit = price.value * profitRate;
total = (price.value*1) + tax + profit;
alert(total);
}
</script>
</head>
<body>
<h2>Perhitungan </h2>
<form name="form_coba" id="form_coba">
Kode barang : <input type="text" name="kode_barang" id="kode_barang"><br>
Harga beli : Rp <input type="text" name="harga_beli" id="harga_beli"><br>
<input type="button" value="Hitung" onclick="Calculate()">
</form>
</body>
</html> ?> |
Selamat Mencoba
 _________________ I'am GinVorteX |
|
| |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|
|
|
|
|
Powered by phpBB © 2001, 2002 phpBB Group
|
|
|
|
|
|
|
|
| |
|
|
|
|
|
|