First, we have a division element that contains the “img” tag. Using Jquery, we will change the “src” attribute of the “img” tag on upload to preview the image. The second element is the “input” tag. It is essential to specify type = “file” in this context.
The most efficient way would be to use URL. createObjectURL() on the File from your <input>. Pass this URL to img. src to tell the browser to load the provided image.
Using HTML, CSS, and JavaScript I need to build a Form with Selection input fields and Radio selection fields. When each one of these fields is selected, I need to build a Preview image based on the selection they made.
Each field will have an Image associated with it and then it will also have that same image replicated for each color.
So if there was 20 Form fields that a user could pick it would have 20 images x 10 different color options and would result in there being 200 possible images to build there preview image!
Here is an image that shows an example of what I am trying to accomplish...the Vans website uses this technique for a custom shoe generator with preview...
When you pick a section and then the color for that section, it loads a transparent image and stacks them together.
For testing, I have made a set of transparent images for a demo form with only 4 Fields and 3 color choices so 12 images in total. (All shown below)
When all the fields have been selected it should build an image preview to the user that is similar to this...
or the Alternative has a Top/Roof more like an octagon type shape
bottom_blue
bottom_green
bottom_red
entrance_blue
entrance_green
entrance_red
top_blue
top_green
top_red
top_red_octo
top_blue_octo
top_green_octo
Here is a basic form that could use the images...
http://jsfiddle.net/Pha4V/
<form id="form-ChannelType"> <p> Select a bottom (just 1 in the demo)<br> <select name="bottom" class="form-control" id="bottom" size="1"> <option value="bottom1">Bottom 1</option> </select> </p> <p> Select a Front (just 1 in the demo)<br> <select name="front" class="form-control" id="front-1" size="1"> <option value="front1">Front 1</option> </select> </p> <p> Select a Top<br> <select name="bottom" class="form-control" id="bottom" size="2"> <option value="bottom_triangle">Triangle Shaped Top</option> <option value="bottom_octo">Octo. Shaped Top</option> </select> </p> <p> Select a Color<br> <select name="color" class="form-control" id="color" size="3"> <option value="blue">Blue</option> <option value="green">Green</option> <option value="red">Red</option> </select> </p> </form>
Can anyone help me in the logic of how to make such a form work? I need to make it work in a way that can easily scale to hundreds of options and images.
With the basic form above, it would need to build a preview image by stacking appropriate images based on the form selections. I don't expect anyone to do all the work for this unless they are simply up for the challenge but I would appreciate any help or ideas on how to best make this work?
NOTE: My final project that will be based off of this will be much different. It will be used for a custom sign generator. I cannot use ImageMagick or GD libraries to do on the fly images, so each image has to be built and each layer changed. Instead of abuilding a simple house structure I will have options such as...
So you can see this will be a pretty big beast when it's all done and I could use any help in getting a good start on it. I don't think a HUGE if/else or switch statement is the best way to go with something like this that can have hundreds of image combinations but I could be wrong?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With