I am new at HTML coding. I've tried to code a calculation for a web site. My purpose is; user enter number and
chose a variable (there are 3 variable button), and when user click on "hesapla" the program should multiple the number with a constat that come from variable. But i've failed. It's basicly like this:
---------------------
<html>
<body
<p> Sayı yazın </p>
<p><input id="sayi" type="text"></p>
<p>Sınıfını Belirleyin</p>
<form>
<input type="radio" name="sinif" value="az"> Az
<br>
<input type="radio" name="sinif" value="normal"> Normal
<br>
<input type="radio" name="sinif" value="cok"> Çok
</form>
<button type="button" onclick="saatbul()">Hesapla</button>
<p id="sure"></p>
<script>
function saatbul()
{
var x=document.getElementById("sayi").value;
var y;
if (element.src.match("az"))
{
y=x*0.5;
}
if (element.src.match("normal"))
{
y=x*0.75;
}
else
{
y=x*0.95;
}
document.getElementById("sure").innerHTML=y;
}
</script>
</body>
</html>
-------------
Could somebody help me?
12-27-2012, 02:30 AM
simplypixie
This is a Javascript question, not HTML.
However, this is what you need (tested):
HTML Code:
<html> <body
<p> Sayı yazın </p> <p><input id="sayi" type="text"></p> <p>Sınıfını Belirleyin</p> <form> <input type="radio" name="sinif" id="az" value="az"> Az <br> <input type="radio" name="sinif" id="normal" value="normal"> Normal <br> <input type="radio" name="sinif" id="cok" value="cok"> Çok </form> <button type="button" onclick="saatbul()">Hesapla</button> <p id="sure"></p> <script>
function saatbul()
{
var x=document.getElementById("sayi").value;
var y;
if (document.getElementById('az').checked)
{
y=x*0.5;
}
else if (document.getElementById('normal').checked)
{
y=x*0.75;
}
else
{
y=x*0.95;
}
document.getElementById("sure").innerHTML=y;
} </script> </body> </html>
12-27-2012, 02:46 AM
alperemir
Thank you very much for your help. It works
Can i ask one more question? Why does it not work in wordpress?
12-27-2012, 02:59 AM
simplypixie
Sorry, I have no idea why it doesn't work in Wordpress as there could be any number of reasons as Wordpress is such a complex system. Maybe ask in a Wordpress forum.
12-27-2012, 03:06 AM
alperemir
Thanks for your help really. I've been trying on these code for several days.