Friends, I am developing an e-commerce and need that after the customer fill out the amount of products and click “Buy”, only products with the field “quantity” to be entered in cart filled.
With business-based applications, you can not rely on javascript to sanitise the information. This is because it’s far too easy for people to also use it to make changes that you do not want to occur.
There have been cases where people have used javascript to provide a negative charge on their credit card, for example. Don’t depend on javascript for your business. You’d be a fool to do so.
The first and most important thing for you to do is to have the server-side filter out the ones without a quantity. Once you have the server doing its correct and proper job, only then is when it is appropriate to have JavaScript help to improve the presentation of things. A nice way of doing that with JavaScript is to send the info to the server, and to then retrieve the sanitised list from the server.
That way your server-side code is doing its job of correctly protecting you, and the scripting is able to help you to display the updated information.
You could also have a separate php script called validateproducts.php which the addtocart.php script uses. The validateproducts.php code is where sanity checks and filtering of items occurs.
That way, you could as a part of later web page development use ajax to request that the products be validated before they get submitted, or other forms of activities such as that.