-2
Talk personal, all right? I’m trying to make a system that calculates budgets depending on the product and its characteristics.
I am using the following code to rescue the data from the database products, in radio Buttons (Pro user have the chance to choose only one at a time)
<p>Selecionar Produto</p> <input type="search" name="" id="">
<div class="results" id="results">
<?php
while ($row = $result->fetch_assoc()){
echo("<input type='radio' id='radio' name='radio' value=".$row['price'].">");
echo ("<label for='radio'>". $row['nome']. "</label> <br>");
}
?>
I was trying to use the $Row['price'] no value with the intention of using this value in Javascript to make the calculations, as follows:
function Calc(){
var price= document.getElementById("radio").getAttribute("value");
price = price * 2 + 0.2;
console.log(price);
}
I was not very successful because Javascript did not only use the Value of the selected item but the first Radio. However precise the calculation, as the above feat is done in the back end in PHP and is returned, I know there is how to do with AJAX, but I have no idea how.
Besides, there is another selectbox that should show the colors of the product, according to the product that was selected in the previous Radio Buttons. How to show only the colors of the selected item (I already have a table with a column containing the colors).
You can’t repeat id’s. Use class instead. An id is like CPF, each person has their own. Imagine if more than one person had the same CPF? How would you identify her? Get the first person with that number? That’s what’s going on in your code. Javascript is taking the first id it finds and ignoring the rest.
– Sam
Welcome to Sopt. Try to be clearer in your question, write it carefully so that others understand what the problem is. Do not mix several topics in the same question. These are some tips to get answers and prevent your question from being closed.
– tvdias
Could justify voting against on https://answall.com/a/434851/172323?
– tvdias
Were you able to verify the answers? Don’t forget to accept one of them.
– tvdias