[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

in img tag, javascript function to get path of image file

Posted on 2005-05-04
5
Medium Priority
?
939 Views
Last Modified: 2012-06-27
As the title implies, I want to call a function, passing a variable or two, that will return the path for a given image file.  In the code below:

              <blockquote class="black-normal-width300">
                <p><img id="img10" src="sunsets2/Nov-2004-sunset-1-sm.jpg" title="Click thumbnail for larger image" onclick='JavaScript: togglePic("img10", src="http://www.somedomain.com/pictures/02-2005/Feb-09-2005-sunset-1.jpg"); return false;' alt=""><br><br>November 2004 sunset 1 of 3</p>
              </blockquote>


I want this:

src="http://www.somedomain.com/pictures/02-2005/Feb-09-2005-sunset-1.jpg"

to be something like:

src= somefunction(var1, var2) + "/02-2005/Feb-09-2005-sunset-1.jpg"


Thanks in advance,
Preece

0
Comment
Question by:Preece
  • 3
  • 2
5 Comments
 
LVL 5

Expert Comment

by:prsupriya
ID: 13933030
Try this...

<head>
<script language="javascript">
function callsrc(){
return "http://www.experts-exchange.com/";
}
</script>
</head>

<body>
<script language="javascript1.2">
imgsrc=callsrc();
document.write("<img src='"+imgsrc+"images/certification.gif'>");      
</script>
</body>
0
 
LVL 12

Author Comment

by:Preece
ID: 13933205
Show how it would be placed in this code block:

              <blockquote class="black-normal-width300">
                <p><img id="img10" src="http://www.somedomain.com/pictures/02-2005/022905-1sm.jpg" title="Click thumbnail for larger image" onclick='JavaScript: togglePic("img10", src="http://www.somedomain.com/pictures/02-2005/022905-1.jpg"); return false;' alt=""><br><br>02/29/2005 pic 1 of 3</p>
              </blockquote>
0
 
LVL 12

Author Comment

by:Preece
ID: 13933247
I'm ok with this part:

<head>
<script language="javascript">
function callsrc(){
return "http://www.experts-exchange.com/";
}
</script>
</head>


but, how would this:

<script language="javascript1.2">
imgsrc=callsrc();
document.write("<img src='"+imgsrc+"images/certification.gif'>");    
</script>
 

be integrated in with:

                <p><img id="img10" src="http://www.somedomain.com/pictures/02-2005/022905-1sm.jpg" title="Click thumbnail for larger image" onclick='JavaScript: togglePic("img10", src="http://www.somedomain.com/pictures/02-2005/022905-1.jpg"); return false;' alt=""><br><br>02/29/2005 pic 1 of 3</p>

Thanks,
Preece
0
 
LVL 5

Accepted Solution

by:
prsupriya earned 1000 total points
ID: 13937494
You can write like this...

<head>
<script language="javascript">
function callsrc(var1,var2){
return var1+var2;
}
</script>
</head>

<body>
<script language="javascript">
imgsrc=callsrc("http://www.somedomain.com/","pictures/");
document.write("<p><img id='img10' src='"+imgsrc+"02-2005/022905-1sm.jpg' title='Click thumbnail for larger image' alt=''><br><br>02/29/2005 pic 1 of 3</p>");
</script>
</body>
0
 
LVL 12

Author Comment

by:Preece
ID: 13938501
Thanks, prsupriya, I'll have a look at this later today...
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

825 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