<ul>
<li><a onclick="apple.a()">10 Яблочек</a></li>
<li><a onclick="cherry.a()">50 Вишенек</a></li>
</ul>
Вкусняшка <div id="fruitname"></div><br>
Сколько <input id="fruithowmany" type="text" onmousedown="this.value=this.value.replace(/([^0-9])/g,'');" onkeyup="var n=this.value.replace(/([^0-9])/g,''); if(n!=this.value) this.value=n;" onchange="changed(this);" maxlength="3" size="1" ><br>
Цена <input type="text" id="price"><br>
<div id="fruitsum"></div>
var apple = {fruitName: 'Яблочки', howMany:10, price:4.21};
var cherry = {fruitName:'Вишенки', howMany:50, price:4.32};
function addel() {
document.getElementById('fruitname').innerHTML = this.fruitName;
document.getElementById('fruithowmany').value = this.howMany;
document.getElementById('fruitprice').value = this.price;
document.getElementById('fruitsum').innerHTML = Math.round(this.price*this.howMany*70)/100; //Замена toFixed(2)
alert('Остальных 30% ворует правительство!');
}
apple.a = addel;
cherry.a = addel;
var fruithowmanyElem = document.getElementById('fruithowmany');
fruithowmanyElem.onkeypress = calc;
fruithowmanyElem.onkeyup = calc;
fruithowmanyElem.oninput = calc;
fruithowmanyElem.onpropertychange = function(){
event.propertyName == "value" && calc();
};
var fruitpriceElem = document.getElementById('fruitprice');
fruitpriceElem.onkeypress = calc;
fruitpriceElem.onkeyup = calc;
fruitpriceElem.oninput = calc;
fruitpriceElem.onpropertychange = function(){
event.propertyName == "value" && calc();
};
function calc(){
var skolko = +fruithowmanyElem.value;
var cena = +fruitpriceElem.value;
var sum;
sum = Math.round(cena*skolko*70)/100;
var otkat = sum*0.3/cena;
alert('Откат правительству составил '+otkat+this.fruitname);
}