There is a choice of delivery type in <input type="radio"> with JS processing; The selected type is displayed like this: <output id="product-price"></output> , but for some reason, when it has not yet made a choice, clicking on an empty line of the order form, this message appears in place of this output [object HTMLParagraphElement] .
What is it and how to deal with it?
Here are the JS code snippets:
window.onload = function(){ totalPrice = "<?=$_SESSION['total_price']?>"; } window.onclick = function onclickRadio() { var nameRadio = document.getElementsByName('nameRadio'); for (var i = 0; i < nameRadio.length; i++) { if (nameRadio[i].type === 'radio' && nameRadio[i].checked) { rezultatRadio = nameRadio[i].value; } } document.getElementById('rezultatRadio').innerHTML = rezultatRadio; document.getElementById('product-price').innerHTML = new Number (+rezultatRadio) + new Number (+totalPrice); } <input type="radio" name="nameRadio" value="300" > Наш курьер (Стоимость доставки 300 руб) <input type="radio" name="nameRadio" value="0">Самовывоз Here is the html output where this warning appears:
<td align="center"><p id="rezultatRadio"></p> руб </td> If you output through, then the following warning appears: [object HTMLOutputElement]
Now I try this code, nothing happens at all ....:
function(){ totalPrice = "<?=$_SESSION['total_price']?>"; } function showResult() { var nameRadio = document.getElementsByName('nameRadio'); for (var i = 0; i < nameRadio.length; i++) { if (nameRadio[i].type === 'radio' && nameRadio[i].checked) { rezultatRadio = nameRadio[i].getAttribute('data'); } } document.getElementById('rezultatRadio').innerHTML = rezultatRadio; document.getElementById('product-price').innerHTML = new Number (+rezultatRadio) + new Number (+totalPrice); } showResult(); window.onclick = showResult; <input type="radio" name="nameRadio" data='300' value="300" checked="checked"> Наш курьер (Стоимость доставки 300 руб) <input type="radio" name="nameRadio" data='0' value="0">Самовывоз
<p>somewhere. no more code can not be said. - zb 'new Number(), not the best option, there is a unary plus, there is aparseIntand so on, use them better - ThisMan