Jump to content

Using jquery to change an image source


Recommended Posts

Hi guys, I'm trying something new so bear with me :P.

 

I have a dropdown box

 

<select id="option" name="number" onchange="changeTeam()">
			<option value="0"></option>
			<option value="1">Team 1</option>
			<option value="2">Team 2</option>
			<option value="3">Team 3</option>
			<option value="4">Team 4</option>
			<option value="5">Team 5</option>
		</select>
<td class="tb">
		<label><img id="Starter1" src="images/Empty.gif" /><br /><input type="radio" id="Starter" name="Starter" value="1" checked="checked" /></label>
	</td>
	<td class="tb">
		<label><img id="Starter2" src="images/Empty.gif" /><br /><input type="radio" id="Starter" name="Starter" value="2" /></label>
	</td>
	<td class="tb">
		<label><img id="Starter3" src="images/Empty.gif" /><br /><input type="radio" id="Starter" name="Starter" value="3" /></label>
	</td>

 

My javascript code is:

 

var Options = Array(['Empty','Empty','Empty'], ['First','Second','Third'], ['Fourth','Fifth','Sixth'], ['Seventh','Eight','Ninth'], ['Tenth','Eleventh','Twelfth'], ['Thirteenth','Fourteenth','Fifteenth']);
function changeTeam(){ 
// this is where I am stuck...
}

 

What I want to do is whenever the drop down changes, a value is picked and from that value, the corresponding array values are replaced.

 

So If I was to pick Team 1, then Empty would be changed to First.gif, Second.gif, Third.gif... I'm not sure on how to do this.. I read somewhere it says using .attr and using .replace(/^(A-z, but I just don't know where to start. So If somoene can shed some light, would be great.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.