Doğru Cevap
-
Ben javascript le cavap vereyim.
a ve b yi form elementlerinin id leri olarak varsayıyorum.
submit butonu yerinede normal bir buton koyalım ve onclick özelliğini "calculate();" yapalım.
<script> var calculate = function() { var a = document.getElementById('a').value; var b = document.getElementById('b').value; var sonuc = 0; switch(a) { case 100: sonuc = b x 0.038; break; case 300: sonuc = b x 0.035; break; case 500: sonuc = b x 0.033; break; default: sonuc = "Hata!"; } alert(sonuc); } </script>
-
solaxay
Arkadaşlar nerde yanlış yaptım acaba ?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<script>
var calculate = function() {
var a = document.getElementById('a').value;
var b = document.getElementById('b').value;
var sonuc = 0;
switch(a) {
case 100:
sonuc = b x 0.038;
break;
case 300:
sonuc = b x 0.035;
break;
case 500:
sonuc = b x 0.033;
break;
default:
sonuc = "Hata!";
}
alert(sonuc);
}
</script>
<form id="b" name="form2" method="post" action="">
<label>
<input type="text" name="b" id="b" />
</label>
</form>
<p> </p>
<form id="a" name="form1" method="post" action="">
<label>
<select name="a" id="a">
<option>100</option>
<option>300</option>
<option >500</option>
</select>
</label>
</form>
<p> </p>
<form id="form3" name="form3" method="post" action="">
<label>
<input type="submit" name="bot" onclick="calculate();" id="bot" value="Submit" />
</label>
</form>
<p> </p>
</body>
</html>12 yıl önce yazılmış -
sevketbulamaz
formlara id verme. yada başka idler ver. yada formları birleştir. ve yine formun idsini farklı bir id yap. html validation'a göre kesin kuraldır. aynı id yi başka bir item için kullanma. en alttaki submit inputun type'ı da "button" olsun. ama javascript kullanırsan bu değerleri başka bir şekilde post etmen gerekir. ya ajax kullanarak post edeceksin yada 3. bir form içindeki hidden bir inputun value'suna eşitleyip o 3. formu post edeceksin. yok ben direk post etmek istiyorum diyorsan javascript işine gelmez. php kullan.
<form id="formB" name="form2" method="post" action=""> <label> <input type="text" name="b" id="b" /> </label> </form> <p> </p> <form id="formA" name="form1" method="post" action=""> <label> <select name="a" id="a"> <option>100</option> <option>300</option> <option >500</option> </select> </label> </form> <p> </p> <form id="form3" name="form3" method="post" action=""> <label> <input type="button" name="bot" onclick="calculate();" id="bot" value="Submit" /> </label> </form>
bu arada neden 3 form kullanmışsın anlamış değilim açıkcası. tek form ile bitirebilirsin bu işi.
<form id="anaForm" name="form" method="post" action=""> <label> <input type="text" name="b" id="b" /> </label> <p> </p> <label> <select name="a" id="a"> <option>100</option> <option>300</option> <option >500</option> </select> </label> <p> </p> <label> <input type="button" name="bot" onclick="calculate();" id="bot" value="Submit" /> </label> </form>
12 yıl önce yazılmış -
solaxay
acemilik işte )) sizlerin sayesinde bir şeyler öğrenmmeye çalışıyorum12 yıl önce yazılmış -
solaxay
arkadaşlar böyle bir hata veriyor
<localhost>
Hata!12 yıl önce yazılmış -
solaxay
Arkadaşlar böyle bir kod buldum bunu benim istediyim hale nasıl getiririm ?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body><head> <title>Çarpma işlemi</title> <body> <form name="theform"> <script language="javascript"> function carp() { ilkdeger = document.theform.ilksayi.value sondeger = document.theform.sonsayi.value sonuc = eval(ilkdeger)*eval(sondeger) document.theform.cevap.value = sonuc } </script> <input name="ilksayi" value="0">x <select name="sonsayi" id="a"> <option>100</option> <option>300</option> <option >500</option> </select>=<input name="cevap" value="0" readonly="1"> <br> <input type="button" value="Hesapla" onClick="carp()"> </form> </body>
12 yıl önce yazılmış -
sevketbulamaz
function carp() { ilkdeger = document.theform.ilksayi.value sondeger = document.theform.sonsayi.value //Bu değerleri switch ile uygularsan switch(sondeger) { case 100: sonuc = eval(ilkdeger)*0.038; break; case 300: sonuc = eval(ilkdeger)*0.035; break; case 500: sonuc = eval(ilkdeger)*0.033; break; default: sonuc = "Hata!"; } document.theform.cevap.value = sonuc; }
12 yıl önce yazılmış -
solaxay
ama yine hata veriyor12 yıl önce yazılmış -
solaxay
arkadaşlar konuyu bir az daa açalim
bu yapmak istediyim sigorta sitesi için
Araba sigortasi için
FRANCHISING 100 300 ve ya 500 olabilir
Phpylede deniye biliriz12 yıl önce yazılmış -
atillaturk83
siz ne yaptınız yaw :D o kadar basit birşey istiyorsun ki kardeşim :) kodu gönderiyorum. sağında solunda düzenleme yaparsın html ya da javascriptle...
<?php
if($_POST["hesapla"]){
$aracdeger = $_POST["aracdeger"];
$yuzde = $_POST["yuzde"];
$sonuc = $aracdeger * $yuzde;
echo $sonuc;
?>
<input type="button" name="geri" value="Geri" onclick="javascript:history.go(-1);" />
<?php
}
else{
?>
<form name="form1" id="form1" method="post" action="fiyat.php">
<input name="aracdeger" type="text" />
<select name="yuzde" >
<option value="3.8">100</option>
<option value="3.5">300</option>
<option value="3.3">500</option>
</select>
<input type="submit" name="hesapla" value="Hesapla" />
</form>
<?php } ?>12 yıl önce yazılmış -
sevketbulamaz
elimde çalışan fonksiyona nasıl hata verdirtiyon çok merak ettim şimdi yaf :)12 yıl önce yazılmış -
atillaturk83
hata verdirtmedim aga yaw :D
karışık kodlar göndermişsiniz adama.. belli ki daha newbie. en basit haliyle yazdım ben de :)12 yıl önce yazılmış -
solaxay
)))) Ya arkadaşlar kusura bakmayin.... Bu dillerden pek anlamam da o yuzden sizi böyle yordum ... )))12 yıl önce yazılmış -
solaxay
Arkadaşlar hepinize çok teşekkür ederim. Sayenizde hallettik. çalıştı.. yinede php :)12 yıl önce yazılmış
-