calling javascript from IMG tag

sharepoint_new
sharepoint_new used Ask the Experts™
on
Hi,
I have a requirement where i need to show gif images based on file extensions in attachments. For that I have written an  xsl where I am calling javascript to check the extension and pass the proper image for that particular extension. Somehow my image tag is not picking that.
I am attaching the code . Please can anyone help me
<SCRIPT LANGUAGE="javascript" DEFER="true">

      [CDATA[ 

		function GetIcon(myFileName)
	{
		var myIcon
		if(myFileName.indexOf(".doc") > -1)
		{
			myIcon = "http://dlglobal.dl.com/_layouts/images/icdoc.gif";
		}
		else if (myFileName.indexOf(".pdf") > -1)
		{
			myIcon = "http://dlglobal.dl.com/_layouts/images/pdf16.gif";
		}
		else if (myFileName.indexOf(".ppt") > -1)
		{
			myIcon = "http://dlglobal.dl.com/_layouts/images/icppt.gif";
		}
		else if (myFileName.indexOf(".xls") > -1)
		{
			myIcon = "http://dlglobal.dl.com/_layouts/images/icxls.gif";
		}

		else
		{
			myIcon = "http://dlglobal.dl.com/PR/BDMarketing/_layouts/AssetUploader.aspx?Size=Small&ImageUrl=%2fPR%2fBDMarketing%2fPublishingImages%2fLondonBrochure%2egif";
		}
		
		return myIcon;
	}

  ]]> 
   
   </SCRIPT>-->
   

<xsl:template match='/Rows'>
<xsl:apply-templates select='Row[position()&lt;=$maxitems]'>
</xsl:apply-templates>
</xsl:template>

<xsl:template match='Row'>
<table border="0" width="100%" cellpadding="2" cellspacing="0">
<tr valign="top">
<xsl:if test="position() = 1">
    <th style="background: #CBCCC0;color: #FFFFFF !important;text-align: center;text-decoration: none;vertical-align: top;font-family: Helvetica !important;font-size: 10pt;font-weight: bold;padding: 5px 5px 5px 15px;" width="75" nowrap="nowrap">Title</th> 
    <th style="background: #CBCCC0;color: #FFFFFF !important;text-align: center;text-decoration: none;vertical-align: top;font-family: Helvetica !important;font-size: 10pt;font-weight: bold;padding: 5px 5px 5px 15px;" width="75" nowrap="nowrap">Date</th> 
   <th style="background: #CBCCC0;color: #FFFFFF !important;text-align: center;text-decoration: none;vertical-align: top;font-family: Helvetica !important;font-size: 10pt;font-weight: bold;padding: 5px 5px 5px 15px;" width="75" nowrap="nowrap">Attachments</th> 
</xsl:if>
</tr>

<tr>
<td style="padding: 5px 5px 5px 15px" width="150" nowrap="false" >
  <xsl:value-of select="Title" /> 
  </td>
<td style="padding: 5px 5px 5px 15px" width="150" nowrap="false" >
  <xsl:value-of select="substring-before(Created,'T')" />
  </td>
  <td style="padding: 5px 5px 5px 15px" width="150" nowrap="false" >
   <a>
  <xsl:attribute name="href">
		<xsl:value-of select="_LinkToAttachment"/>
		<IMG style="border-style: none" alt="" src="GetIcon(_LinkToAttachment)" /> 
</a>
	


</td>
</tr>
</table>
</xsl:template>
  </xsl:stylesheet>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2007

Commented:
I question your use of the "defer" attribute in your JavaScript block. Do you know what this does?

This might be the problem:

<IMG style="border-style: none" alt="" src="GetIcon(_LinkToAttachment)" />

Perhaps it should be:

<IMG style="border-style: none" alt="" src="GetIcon(" + _LinkToAttachment + ")" />
Top Expert 2007

Commented:
Any way to see what the value of this really is?

<xsl:value-of select="_LinkToAttachment"/>

>_LinkToAttachment< is not referenced in your example is why I ask.
We have implemented it through Jquery. Thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial