0
I made an iframe that shows products from another file. html, there is realized a product of product price and the quantity selected with the result of that product showing there same.
However, I would like to take the values of all these results, sum it all up and show the total outside of this iframe, in the original document.
I need this for another project, where I will put new product categories on src
'different s of the same iframe, with the total of all in the first document.
Follows the code:
HTML (Page where iframe is)
<body>
<iframe src="outro.html" frameborder="0" width="500px" height="500px"></iframe>
<p>Total: R$<span id="total">0</span></p>
</body>
HTML (Page that is src
iframe)
<body>
<div class="itens">
<p id="topo">Produto 1</p>
<p id="tipo">Tipo: <b>Brinquedo</b></p>
<p id="pre">Preço: <b>R$50</b></p><br>
<p id="qtd">Quantidade:<br><input type="number" id="qtd" min="0" max="99" value="0" onmouseup="calc(this.value, 'brinquedo', 50)"> </p>
<p id="tot">Total: <br>R$<span id="brinquedo" name="valor">0</span></p>
</div>
<div class="itens">
<p id="topo">Produto 2</p>
<p id="tipo">Tipo: <b>Brinquedo</b></p>
<p id="pre">Preço: <b>R$100</b></p><br>
<p id="qtd">Quantidade:<br><input type="number" id="qtd" min="0" max="99" value="0" onmouseup="calc(this.value, 'brinquedo2', 100)"> </p>
<p id="tot">Total: <br>R$<span id="brinquedo2" name="valor">0</span></p>
</div>
</body>
Javascript (Function I used pro calculus)
let total = 0;
function calc(q, v, t){
total = (q * t)
document.getElementById(v).innerHTML = total;
calc_total()
}
function calc_total(){
let b1 = parseFloat(document.getElementById('brinquedo').innerHTML);
let b2 = parseFloat(document.getElementById('brinquedo2').innerHTML);
valTotal = b1 + b2
document.getElementById('total').innerHTML = valTotal
}
The calculation is done in the iframe or in the original document?
– Sam
The calculation is done in the iframe
– Henrique
Try
window.parent.document.getElementById('total').innerHTML = valTotal
– Sam