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
https://forums.phpfreaks.com/topic/262037-using-jquery-to-change-an-image-source/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.