dear all,
for 2 day ago, i have re-read and re-write my code
in first i have very very broken code execution in web
in second : being supported by mr. twain (thanks for support), i re write the code and in previewer browser ( i use mozilla 3.6.8) its work off line, but when i have implanting in web page, its not work, :(,
in 3rd, with mr.airshow support i have rewrite and it work on web page (thanks mr. airshow)
but still in my mind, again :
Question :
1. Why the 2nd code can not execution in web page ?
2. How the code must be to load in web page ? Any rules ?
here are the code :
<script language="JavaScript">
function hitungmbr(formID) {
var formObj = document.getElementById(formID)
if (formObj) {
var bb = parseFloat(formObj.bb.value, 10);
var tb = parseFloat(formObj.tb.value, 10);
var umur = parseFloat(formObj.umur.value, 10);
var kelamin = parseInt(formObj.kelamin.options[formObj.kelamin.selectedIndex].value, 10); // menunjuk value pilihan jenis kelamin
if (kelamin==0) { // digunakan dengan pilihan langsung pada bagian pilihan ke-1 :laki-laki
formObj.bmr.value = 66 + (bb * 13.7)+(tb *5)- (umur * 6.8);
// Rumus aslinya = 66 + ( 13.7 x berat kg ) + ( 5 x tinggi cm ) - ( 6.8 x umur tahun )
}
else { // ini bila kita tidak memilih di pilihan satu :perempuan maka rumus yang dipakai menjadi
formObj.bmr.value = 655 + (bb*9.6)+(tb *1.8)- (umur * 4.7);
// Rumus aslinya = BMR = 655 + ( 9.6 x berat kg ) + ( 1.8 x tinggi cm ) - ( 4.7 x umur tahun )
}
}
}
function hitungkalori(formID) {
var formObj = document.getElementById(formID)
if (formObj) {
var bmr = parseFloat(formObj.bmr.value, 10);
var kegiatan = parseInt(formObj.kegiatan.options[formObj.kegiatan.selectedIndex].value, 10); // menunjuk pilihan jenis kegiatan
if (kegiatan==0) {
formObj.kalori.value = bmr * 1.2;
}
if (kegiatan==1) {
formObj.kalori.value = bmr * 1.375;
}
if (kegiatan==2) {
formObj.kalori.value = bmr * 1.55; }
if (kegiatan==3) {
formObj.kalori.value = bmr * 1.725;
}
if (kegiatan==4) {
formObj.kalori.value = bmr * 1.9;
}
}
}
</script>
<form action="" method="post" name="penghitungkaloriharian" id="penghitungkaloriharian">
<table width="358" border="1" bgcolor="#FFFF91" summary="Adalah tabel yang digunakan untuk menghitung kebutuhan kalori harian anda. Tabel ini mempresentasikan kebutuhan kalori anda berdasarkan jenis kelamin dan jenis kegiatan harian anda. Di adaptasi dari Penghitungan Harris-Benedict.">
<caption align="top" class="style6">
Tabel Penghitung Kebutuhan Kalori
</caption>
<tr>
<th width="186" class="style3" scope="col"><div align="left" class="style3">
<div align="right">Saya adalah seorang : </div>
</div></th>
<th width="173" scope="col"><div align="left">
<select name="kelamin" size="1" class="style6" id="kelamin">
<option selected value=0>Laki - laki</option>
<option value=1 >Perempuan</option>
</select>
</div></th>
</tr>
<tr>
<td class="style3"><div align="right">Berat Badan </div></td>
<td><input name="bb" type="text" class="style6" id="bb" size="4">
<span class="style5">kg</span> </td>
</tr>
<tr>
<td class="style3"><div align="right"><span class="style1">Tinggi Badan </span></div></td>
<td class="style5"><input name="tb" type="text" class="style6" id="tb" size="4">
cm </td>
</tr>
<tr>
<td class="style3"><div align="left" class="style1">
<div align="right">Umur<span class="style7"> </span></div>
</div></td>
<td><input name="umur" type="text" class="style6" id="umur" size="4">
<span class="style5">tahun </span></td>
</tr>
<tr>
<td colspan="2"><div align="center"><span class="style1">
<input name="Button" type="button" class="style3" value="Hitung BMR" onclick = "hitungmbr('penghitungkaloriharian')" >
</span></div></td>
</tr>
<tr>
<td class="style3"><div align="right">BMR anda : </div></td>
<td><input name="bmr" type="text" class="style9" id="bmr" size="5" readonly></td>
</tr>
<tr>
<td height="33"><div align="right"><span class="style1">
<span class="style3">Jenis kegiatan yang akan anda lakukan sehari- hari :</span>
</span></div></td>
<td><select name="kegiatan" size="1" class="style6" id="kegiatan">
<option selected value=0>Tanpa Kegiatan</option>
<option value=1>Kegiatan Ringan</option>
<option value=2>Kegiatan Sedang</option>
<option value=3>Kegiatan Berat</option>
<option value=4>Kegiatan Sangat Berat</option>
</select></td>
</tr>
<tr>
<td colspan="2" class="style3"><div align="center"><span class="style1">
<input name="Button" type="button" class="style3" value="Hitung Kalori Harian" onclick = "hitungkalori('penghitungkaloriharian')">
</span></div></td>
</tr>
<tr>
<td><div align="right"><span class="style3">Kalori yang anda butuhkan dalam sehari : </span></div></td>
<td><input name="kalori" type="text" class="style10" id="kalori" size="5" readonly>
<span class="style10">kalori </span></td>
</tr>
</table>
<p> </p>
<p class="style4"> </p>
</form>
Please,
anybody can help explaining that ?
very thanks.