Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
64
rated 0 times [  70] [ 6]  / answers: 1 / hits: 32511  / 14 Years ago, thu, july 8, 2010, 12:00:00

I'm trying to use JS to dynamically replace an image on a page based upon the value of the selected option of a select dropdown. Everything in the code I've included below works perfectly. My selected_text variable is properly pulling the value of the selected option in my select dropdown, but I need to somehow write that value to the replacement img src path.



IE: If someone selects Audi from my select dropdown, I want to write Audi where I have [selected_text] in my replacement img src path.



Any ideas?



<script type=text/javascript>
function popmake() {
var w = document.vafForm.make.selectedIndex;
var selected_text = document.vafForm.make.options[w].text;
document.getElementById('make-image').src=/path/to/images/[selected_text].jpg;
}
</script>

More From » javascript

 Answers
57

what about



document.getElementById('make-image').src=/path/to/images/ + selected_text + .jpg;

[#96295] Tuesday, July 6, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kamronr

Total Points: 749
Total Questions: 110
Total Answers: 122

Location: Dominica
Member since Sat, Nov 5, 2022
2 Years ago
kamronr questions
Mon, Dec 21, 20, 00:00, 3 Years ago
Fri, Oct 16, 20, 00:00, 4 Years ago
Sat, Oct 3, 20, 00:00, 4 Years ago
Sun, Jul 28, 19, 00:00, 5 Years ago
;