I have managed to get this working with a basic dropdown menu field (see the preview section to the right of the page below).
https://www.pacifichelmets.com/index.ph ... uest-quote
However I cannot seem to integrate this functionality with a working contact form (see "Shell Colour" field at left), as the "<select>" fields seem to be creating a double up; which obviously breaks the field. For reference I basically added the same code into the contact field's "JavaScript for field:" area via the "Advanced Settings" tab.
I'm not very good with javascript so my code is basically just a reworked version what I've been able to find online:
contact form
Code: Select all
<form method="" action="" name="myForm">
<select name="switch" onchange="switchImage();">
<option value="1">White</option>
<option value="2">Red</option>
<option value="3">Rescue Blue</option>
<option value="4">Black</option>
<option value="5">Fluorescent Lime</option>
<option value="6">Helmet Orange</option>
<option value="7">Daisy Yellow</option>
</select>
</form>
Code: Select all
<img src="img/structural/F15/F15-3-Shell-1.png" width="561" height="470" name="myImage" />
Code: Select all
{literal}
<__script__>
// This is the code to preload the images
var imageList = Array();
for (var i = 1; i <= 7; i++) {
imageList[i] = new Image(70, 70);
imageList[i].src = "img/structural/F15/F15-3-Shell-" + i + ".png";
}
function switchImage() {
var selectedImage = document.myForm.switch.options[document.myForm.switch.selectedIndex].value;
document.myImage.src = imageList[selectedImage].src;
}
</__script>
{/literal}
