Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Change image based on user selection
Old 10-09-2007, 11:05 PM Change image based on user selection
Junior Talker

Posts: 2
Trades: 0
I found the following code to change text based on user selection from a drop down list. I want to do the same thing, only I want to change an image based on the user selection.

Any ideas?

Thanks for the help!

<script type="text/javascript">
var textBlocks = new Array(
'Select a member',
'Member 1 text.',
'Member 2 text.');
function changetext(elemid) {
var ind = document.getElementById(elemid).selectedIndex;
document.getElementById("display").innerHTML=textB locks[ind];
}
</script>
</head><body>
<form>
<select id="whatever" onchange="changetext('whatever');">
<option value="0">Select</option>
<option value="1">Member1</option>
<option value="2">Member2</option>
</select><br>
</form>
<div id="display">Select a member</div>
</body></html>
jzieba is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-10-2007, 02:06 AM Re: Change image based on user selection
ForrestCroce's Avatar
Half Man, Half Amazing

Posts: 3,023
Name: Forrest Croce
Location: Seattle, WA
Trades: 0
document.getElementById(image).src = "something.jpg"

Put that in the onchange for the drop down.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
ForrestCroce is offline
Reply With Quote
View Public Profile Visit ForrestCroce's homepage!
 
Old 10-10-2007, 09:11 AM Re: Change image based on user selection
Junior Talker

Posts: 2
Trades: 0
Thanks ForrestCroce. Can you provide a little more clarification. I am totally new to java script.

Where does this fit in the code? Don't I need a variable for the src rather than a fixed image like "something.jpg"?

Thanks again for the help.
jzieba is offline
Reply With Quote
View Public Profile
 
Old 05-14-2009, 09:55 PM Re: Change image based on user selection
Junior Talker

Posts: 1
Trades: 0
Quote:
Originally Posted by ForrestCroce View Post
document.getElementById(image).src = "something.jpg"

Put that in the onchange for the drop down.
Can this be done with alphanumeric (words) values as opposed to the numeric(numbers) values?

I want to use this script to change a text caption and image based upon the users selection in a drop-down box. I found this same script and it seems to be dependent on numbers as the option value. I need this to work with words as the option value. Does anyone have a working example or idea on how to do this? thanks
arc1 is offline
Reply With Quote
View Public Profile
 
Old 05-18-2009, 09:05 PM Re: Change image based on user selection
Sleeping Troll's Avatar
Ultra Talker

Posts: 351
Name: Butch Begy
Trades: 0
Do yourself a favor and take a quick tutorial, it appears to me that you are not at all familiar with objects, methods, properties and classes... Get familiar and you will have a much easier time with any language you tackle.

http://w3schools.com
__________________
Sleeping Troll, EMUSE, Mind Expansion...Truly serendipity!
Sleeping Troll is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Change image based on user selection
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.37941 seconds with 12 queries