Kod: Zaznacz cały
var wynik = document.getElementById("result").value * 0.1;
var suma = document.getElementById("result").value + wynik;
document.write(suma);
Kod: Zaznacz cały
var wynik = document.getElementById("result").value * 0.1;
var suma = document.getElementById("result").value + wynik;
document.write(suma);
Kod: Zaznacz cały
tmp_val = document.getElementById("result").value;
wynik = (tmp_val * 0.1) + (tmp_val*1);
document.write(wynik);
żeby uniknąć zbędnych przemnożeń z powyższego rozwiązania
Kod: Zaznacz cały
tmp_val*1Zamiast document.write() zwracaj wynik do jakiegoś pola input lub do div'a przez innerHTML.jak to zrobic, zeby wynik pojawial mi sie od razu bez przeladowywania strony (ajaxem?)?
Kod: Zaznacz cały
function funkcja() {
var tmp_val = document.getElementById("result").value;
var wynik = (tmp_val * 0.15) + (tmp_val*1);
var procent = tmp_val * 0.15;
document.write("procent: ");
document.write(procent);
document.write("<br />suma z procentem: ");
document.write(wynik);
document.write("<br />suma bez procentu: ");
document.write(tmp_val);
document.write("<br /><a href=\"javascript:history.go(-1)\">cofnij</a>");
}Kod: Zaznacz cały
<input type="button" value="procent" onClick="funkcja()">Kod: Zaznacz cały
function funkcja() {
var tmp_val = document.getElementById("result").value;
var wynik = (tmp_val * 0.15) + (tmp_val*1);
var procent= tmp_val * 0.15;
document.innerHTML(procent);
document.innerHTML(wynik);
document.innerHTML(tmp_val);
//document.write("<br /><a href=\"javascript:history.go(-1)\">cofnij</a>");
}Kod: Zaznacz cały
<input type="button" value="procent" onClick="funkcja(document.innerHTML('procent').value,document.document.innerHTML('wynik').value)" />Kod: Zaznacz cały
<html>
<head>
<script>
function licz(){
var tmp_val = document.getElementById("result").value;
var wynik = (tmp_val * 0.15) + (tmp_val*1);
var procent= tmp_val * 0.15;
cnt_html = "Procent: "+procent+"<br />";
cnt_html+= "Suma z procentem: "+wynik+"<br />";
cnt_html+= "Suma bez procentu: "+tmp_val;
inner_div('d_return',cnt_html);
}
// -------------------------------------------------------------
function inner_div(el,cnt){
obj = document.getElementById(el);
obj.innerHTML = cnt;
}
</script>
</head>
<body>
<input type="text" id="result" value="0"/>
<input type="button" name="b_licz" onclick="licz();" value="Wywolaj funkcje"/>
<div id="d_return" style="border: 1px solid #444;"></div>
</body>
</html>