Solved

change img src with jQuery

Posted on 2011-02-28
3
1,875 Views
Last Modified: 2012-05-11
I don't understand why I can't chnage the image by chaning the src. What am I doing wrong?


<td id="TagLine" colspan="2" align="right"><?php echo '<img id="DoYouMeasureUp" src="'.BASEURL .$taglinefile .'" alt="'.$_SESSION['lang']['tagline'] .'" width="296" height="44"/>'?>
	</td>

Open in new window


I added this in a jQuery and tried all three different ways to define path to file
	$("#sLangSelect").live('change', function(){
		
		var myLanguage = $(this).val();
		//runReport();
		//$("#headerSection").load('/aaMain/header.php');
		switch (myLanguage)
		{
			case '1':
				
				$('img').attr('src') = '/images/do-you-measure-up-english.gif';
	
				break;
			case '2':
				
				$('#DoYouMeasureUp').attr('src')= "images/do-you-measure-up-french.gif";
			
				break;
			case '3':
				
				$('#DoYouMeasureUp').attr('src')= "http://dev.secure.emetrixsystems.com/images/do-you-measure-up-spanish.gif";
				
				break;
		}
		
		
	/*	var rt = $.ajax({
	   type: "POST",
	   url: "/aaMain/header.php?ulang="+$(this).val(),
	   //data: $("form[name=filters]").serialize(),
	   success: function(msg){
$("#headerSection").html(msg); }
});*/

		
});
       

Open in new window

0
Comment
Question by:gbeaulac
  • 2
3 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 34998131
For example :

$('img').attr('src', '/images/do-you-measure-up-english.gif');

Open in new window


and not :

$('img').attr('src') = '/images/do-you-measure-up-english.gif';

Open in new window

0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 34998147
with select the image by its id and not it tag, use the # :


$
('#imgId').attr('src', '/images/do-you-measure-up-english.gif');

Open in new window

0
 

Author Closing Comment

by:gbeaulac
ID: 34998180
You are the Man!!!
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now