I want to learn how to display combined images with help of checkboxes. Lets say I have three images, the first one is a car, second one is the same car with new wheels on the car, third is is the same car but with tinted windows, fourth one is the car with both assets combined. I always display the original image of the car on the website higher and new one(tuned one) lower, but lets say if I click the box for new wheels it shows the second image or if I click tinted windows box, third image appears. The images are prepared with photoshop and stored in folder, simple stuff.
<form action="#" method="post">
<input type="checkbox" name="option" value="Wheels">Wheels</input>
<input type="checkbox" name="option" value="Tint">Windows</input>
<input type="submit" name="submit" value="Submit"/>
</form>
<?php
if (isset($_POST['option'])){
// Display.
}
?>
I made a simple form so far and lets say as I said if I check Wheels
, the wheels appear on the car, I uncheck it they disappear. But how could I do that if I check both boxes, the fourth image appear? I would like a solution that if I had more different check boxes, I would not need to code a lot of statements
I am not asking for a code, but just ideas how to do it, because my idea is to hard code many if statements.
EDIT: I am sorry if this is maybe a duplicate, but I strongly want to implement this using PHP, because lets say a person might click n
different combinations of how the car should look if there are more than 20 checkboxes and he wants to add different components to the car.
2
Answers
try this code:-
You say that you want to do this using PHP.
As the comments state, and my duplicate flag indicates, this is not necessary.
You can look at the GD library about layering images, skip CSS completely, and just link to that image.
Another PHP based approach is this:
This takes your input, and create an
<img>
element for each option, with the CSS class that places it on top of the base car image.This is just as easy to do in javascript
Disadvantage of PHP:
Advantages of Javascript solution:
Other things to take in to account: