I have 2 drop down boxes to select products and a div for a shopping cart.
<select id="RAM">
<option value="1">4 GB</option>
<option value="2">8 GB</option>
</select>
<select id="HDD">
<option value="1">300 GB</option>
<option value="2">500 GB</option>
</select>
<ul id="cart">
<li>PRODUCT NAME (PRICE)</li>
<li>PRODUCT NAME (PRICE)</li>
</ul>
and I want to pass this dropdown value to a PHP file using AJAX and return product name & Product price etc, to #cart as a <li> with out refreshing page. and also without repeating the same product. Please suggest me a good/secure way to do this.
- Client can always change what he choose Ex: 4 GB RAM to a 8GB RAM.
Firstly, create form:
And ajax code (I use jQuery library because of its compatibility with all browsers):
Now you have to write PHP script:
I think you want to save users choices. If I’m right, add saving products to cookies or database.
Cookie example:
I hope it is useful for you 🙂