Transmit the quantity button number to another page

Perhaps you want to transmit the value of the quantity button + – with a products that you are selling on your website but you don’t know a lot about javascript.

Here is a script that prevent to get a negative number :

plus minus

And now you want to transmit the quantity to your basket, or limit the quantity in order that it won’t be over the stock one available in you database with the $stock variable.

To limit the quantity, you need to add a condition with the function add() :

function add( name ) {
    if (document.getElementById( name ).value < 0) {
        document.getElementById( name ).value ++; 

You could also use an input with the type number to generate the field quantity, the only issue is that it is not displayed the same way on the different browser.

To send the quantity to your basket, you can use a form, for example :

plus minus

The POST method would be more appropriate for this form to avoid to have urls full of parameters. But the GET method will allow you to verify easily the information during the development. By submitting the form, you should get the URL that will add the value to the basket.

PS : don’t forget to add the name attribute to the input balises, it will be that name that will be used to get the parameter in PHP via =_GET[‘yourquantityattribute’] or $_POST[‘yourquantityattribute’].