The code will defer from theme to theme. I have created code to work on DAWN theme. The following code will detect the quantity change. Dpo modify the code as per your requirement.
document.querySelector('[name="quantity"]').addEventListener('change', function(t){
document.querySelector('#message').innerHTML = `Your Quantity is ${t.target.value}`
})
Where do I need to place the first code block exactly?
And second question:
In case I just wanted to have a variable {{ selectedQuantity }} available in the custom liquid code block, so that I can generate the message from there based on some checks, would that also be possible?