0

Hey guys i'm wondering if you could help me figure out this problem ive been having. im trying to get the weight of a product to add or subtract itself whenever a plus or minus button is clicked on.

I've established my weight from the database and set an id to that weight. then in javascript I've used getElementByid and added my weight id like so:

 <span id="weight"><?php echo ( $value['weight'] );  ?></span> kg<br/>
    <button onclick="minus()"> - </button><span id="quantity"> 1 </span><button onclick="plus()"> + </button><br/>  

<script>

function plus(){

    // parseint changes strings into intergers 

    document.getElementById('weight').innerHTML = parseInt( document.getElementById('weight').innerHTML) +weight;

}
function minus(){

    document.getElementById('weight').innerHTML = parseInt( document.getElementById('weight').innerHTML) -weight;

}

<script>


when i go onto the front end and press the add or minus button theres a message that comes up [object HTMLSpanElement] kg. just wondering what i did wrong here?

0 Answers0