Доброго времени суток.
Столкнулся с проблемой, что при подсчете количества введенных слов функция отказывается выполнять умножение с ценой из другой функции...
Первая функция:
function calc() {
var type_host = document.getElementById("type_host");
var seo = document.getElementById("seo");
var comment = document.getElementById("comment");
var gallery = document.getElementById("gallery");
var eshop = document.getElementById("eshop");
var result = document.getElementById("type_host");
var result = document.getElementById("seo");
var result = document.getElementById("comment");
var result = document.getElementById("gallery");
var result = document.getElementById("eshop");
var result = document.getElementById("result");
var price_host = 0;
var price_seo = 0;
var price_comment = 0;
var price_gallery = 0;
var price_eshop = 0;
var price = 0;
price_host += (type_host.checked == true) ? parseInt(type_host.value) : 0;
price_seo += (seo.checked == true) ? parseInt(seo.value) : 0;
price_comment += (comment.checked == true) ? parseInt(comment.value) : 0;
price_gallery += (gallery.checked == true) ? parseInt(gallery.value) : 0;
price_eshop += (eshop.checked == true) ? parseInt(eshop.value) : 0;
price=price_host+price_seo + price_comment + price_gallery + price_eshop;
result_host.innerHTML = price_host;
result_seo.innerHTML = price_seo;
result_comment.innerHTML = price_comment;
result_gallery.innerHTML = price_gallery;
result_eshop.innerHTML = price_eshop;
result.innerHTML = price;
}
Вторая функция:
var textarea = document.getElementsByName("comments")[0];
var counter = document.getElementById("counter");
textarea.onkeyup = function(s) {
counter.innerHTML = this.value.split(/ +(?:\S)/).length;
}
Сам код:
<td width="20px"><input type="checkbox" onchange="calc()" value="350" id="type_host" /></td>
<td width="60px"></td>
<td width="100px"><span id="result_host">0</span> руб.</td>
<td width="20px"><input type="checkbox" onchange="calc()" value="300" id="seo" /></td>
<td width="60px"></td>
<td width="100px"><span id="result_seo">0</span> руб.</td>
</tr>
<tr>
<td width="20px"><input type="checkbox" onchange="calc()" value="300" id="comment" /></td>
<td width="60px"></td>
<td width="100px"><span id="result_comment">0</span> руб.</td>
<td width="20px"><input type="checkbox" onchange="calc()" value="300" id="gallery" /></td>
<td width="60px"></td>
<td width="100px"><span id="result_gallery">0</span> руб.</td>
</tr>
<tr>
<td width="20px"><input type="checkbox" onchange="calc()" value="200" id="eshop" /></td>
<td width="60px"></td>
<td width="100px"><span id="result_eshop">0</span> руб.</td>
<td width="20px"></td>
<td width="60px"></td>
<td width="100px"></td>
</tr>
<tr>
<td colspan="6" align="center"><h3>Введите текст:</h3></td>
</tr>
<tr>
<td colspan="5"><textarea name="comments" onchange="calc()" value="0" cols="38" rows="7"></textarea></td>
<td>Введено слов: <span id="counter">0</span></td></tr>
<tr><td colspan="6"><center><input type="submit" value="Отправить"> <input type="reset" value="Очистить"></center></td>
</tr>
<tr>
<td width="80" colspan="2" class="td_result">ИТОГО:</td>
<td width="120" colspan="2"></td>
<td width="160" class="td_result" colspan="2"><span id="result">0</span> руб.</td>
</tr>
Что необходимо прописать, чтобы перемножить результат result с counter???