Autor Zpráva
honzonator
Profil *
ahoj, muze mi prosim nekdo vysvetlit proc mi nejde nasledujici javascript:

<html>
<head>
<script>
function calculate(price,total,quantity){

var quantity
var total

quantity = document.getElementById(quantity).value;
total = quantity*price;


alert(total);
document.getElementById(total_price_8).value = total;



}

</script>
<head>
<body>

<table border="1">

<tr>
<th>ID</th>
<th>Type</th>
<th>Name</th>
<th colspan='2'>Price</th>
<th>Image</th>
<th>Quantity</th>
<th></th>
<th>Total</th>
</tr>

<tr>
<td>8</td>
<td>fruit</td>
<td>apple</td>
<td width='30px'>2.60</td>
<td width='30px'>per kg</td>
<td width='100px' height='100px'>
<img src='IMAGES/PRODUCTS/apple.jpg'></td>
<td><input type='text' style='width:40px' id='quantity_8'></td>
<td><input type='button' value='ADD!' style='width:50px' onClick="calculate(2.60,'total_price_8','quantity_8')"></td>
<td><input type='text' style='width:80px' id='total_price_8'></td>
</tr>
</table>
</body>
</html>

ten alert tam mam jen proto, abych zjistil jestli to pocita.

Dekuju Honzik
Hugo
Profil
<html>
<head>
<script>
function calculate(price,total,quantity){

quantity = document.getElementById(quantity).value;
total = quantity*price;


alert(total);
document.getElementById('total_price_8').value = total;



}

</script>
<head>
<body>

<table border="1">

<tr>
<th>ID</th>
<th>Type</th>
<th>Name</th>
<th colspan='2'>Price</th>
<th>Image</th>
<th>Quantity</th>
<th></th>
<th>Total</th>
</tr>

<tr>
<td>8</td>
<td>fruit</td>
<td>apple</td>
<td width='30px'>2.60</td>
<td width='30px'>per kg</td>
<td width='100px' height='100px'>
<img src='IMAGES/PRODUCTS/apple.jpg'></td>
<td><input type='text' style='width:40px' id='quantity_8'></td>
<td><input type='button' value='ADD!' style='width:50px' onClick="calculate(2.60,'total_price_8','quantity_8')"></td>
<td><input type='text' style='width:80px' id='total_price_8'></td>
</tr>
</table>
</body>
</html>
honzonator
Profil *
dikes,
ty uvozovky by me meli kopat pokazdy kdyz je vynecham
honzonator
Profil *
Vlastne jinak, ten total musi zustat takhle, protoze si to id automaticky generuje php. No a ja myslel, ze kdyz to mam ve funkci definovany jako total, tak to tak muzu dat i do document.get......


<html>
<head>
<script>
function calculate(price,total,quantity){

var quantity
var total

quantity = document.getElementById(quantity).value;
total = quantity*price;

document.getElementById(total).value = total;



}

</script>
<head>
<body>

<table border="1">

<tr>
<th>ID</th>
<th>Type</th>
<th>Name</th>
<th colspan='2'>Price</th>
<th>Image</th>
<th>Quantity</th>
<th></th>
<th>Total</th>
</tr>

<tr>
<td>8</td>
<td>fruit</td>
<td>apple</td>
<td width='30px'>2.60</td>
<td width='30px'>per kg</td>
<td width='100px' height='100px'>
<img src='IMAGES/PRODUCTS/apple.jpg'></td>
<td><input type='text' style='width:40px' id='quantity_8'></td>
<td><input type='button' value='ADD!' style='width:50px' onClick="calculate(2.60,'total_price_8','quantity_8')"></td>
<td><input type='text' style='width:80px' id='total_price_8'></td>
</tr>
</table>
</body>
</html>
Hugo
Profil
honzonator

To nepoběží, používáš jednu proměnnou na dvě různé věci (jako id prvku a jako celkovou cenu).
honzonator
Profil *
Nejaky doporuceni?
honzonator
Profil *
Jsem pitomej, ingnoruj prosim predchozi otazku. Proste zmenit jmeno pole preci :)
honzonator
Profil *
muzu se jeste zeptat, jak omezim ten vysledek jan na dve desetiny mista?

Vaše odpověď


Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm:

0