Change output on option select
Hey all,
I'm having some trouble with what seems to be a fairly simple issue: I have a <select> field with a few options inside of it. The idea is that a user can select an option in this dropdown and, dependent on what they choose, the output in another div with change.
The form:
- <form class="formStyle">
- <fieldset>
- <label for="soFormStyle">style:</label>
- <select name="soFormStyle" id="soFormStyle">
- <option>Select Style</option>
- <option>Page Curl</option>
- <option>Logo</option>
- </select>
- </fieldset>
- </form>
The output div:
- <div class="formPreview">
- <div class="previewWindow">
- <img id="formPreviewImage" src="img/form-slim-plain.jpg" width="450">
- </div>
- </div>
My current JQuery:
- switch ($('#ssFormStyle :selected').text()) {
- case 'Page Curl':
- $('#formPreviewImage').attr({src: "img/form-slim-pagecurl-plain.jpg",})
- break;
- case 'Logo':
- $('#formPreviewImage').attr({src: "img/form-slim-logo-plain.jpg",})
- break;
- };
So, this JQuery only works if the option is preselected (if I select and reload the page). I thought I was on the right track, but I just can't get it working as I intended. Again, the idea is that a user selects "Page Curl" or "Logo", and the image in the preview pane changes according to their selection.
Any help would be much appreciated. Thanks in advance.