Link to home
Start Free TrialLog in
Avatar of Preece
PreeceFlag for United States of America

asked on

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

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

Avatar of prsupriya
prsupriya

Try this...

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

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

ASKER

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>
Avatar of Preece

ASKER

I'm ok with this part:

<head>
<script language="javascript">
function callsrc(){
return "https://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
ASKER CERTIFIED SOLUTION
Avatar of prsupriya
prsupriya

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Preece

ASKER

Thanks, prsupriya, I'll have a look at this later today...