When i try to change the value of this input nothing works

i get no errors in the console as well
html

<td class="quantity-box"><input type="number" size="4" value="1" min="0" step="1" class="c-input-text qty text"></td>
                                    <td class="total-pr">
                                        <p>$ 80.0</p>```

javascript


if	(document.readyState == `loading`)
	{document.addEventListener(`DOMContentLoaded`,ready);}
else{ready}
function ready(){const removebutton = document.querySelectorAll(`.remove-pr`);
 console.log(removebutton);
for( let i=0 ; i < removebutton.length; i++){	
	const button = removebutton[i]
	button.addEventListener(`click`,function(event){
		var buttonclicked= event.target
		buttonclicked.parentElement.parentElement.parentElement.remove()
	updatecarttotal()})}	
var value = document.getElementsByClassName(`cart-quantity-input`)
  for( let i=0 ; i < value.length; i++){
	  var input = value[i]
	  console.log(value);
	  input.addEventListener(`change`, quantityChanged)
	  console.log(value);
  }
	function quantityChanged(event){
		var input = event.target
		if(isNaN(input.value) || input.value <=5 ){
			input.value = 1
		}
		updatecarttotal()
}
function updatecarttotal() {
   var cartitemcontainer = document.getElementsByClassName(`table`)[0]
    var removebutton = document.querySelectorAll(`.cart-items`)
    var total =0
    for( let i= 0 ; i < removebutton.length; i++){
   	 var removebutton = removebutton[i]
   	 var priceelement = removebutton.getElementsByClassName(`price-pr`)[0]
   	 var quantitylement = removebutton.getElementsByClassName(`cart-quantity-input`)[0]
   	 
   	 
   	 var price =parseFloat(priceelement.innerText.replace(`$`,``))
   	 var quantity = quantitylement.value
   	 total = total + (price*quantity)
   	 
   	 document.getElementsByClassName("d-flex-gr-total")[0].innerText=`$`+total;
   	 console.log(quantitylement)		 }
 
   }
}

Right now your JavaScript is referencing HTML elements that doesn’t exist (for example, where is the element with a class cart-quantity-input?)

Use something like codepen.io to create a runnable example.

now it works i just had to call this class "c-input-text qty text" .
i had a class named cart-quantity-input but it wasnt the right one
so i think i was pressing on the button but i was calling the wrong class thats why noting happened your comment made me realise that so ty :slight_smile:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.