I have a metadata with the name "productiondescription", in my advanced search, I want to display this "productiondescription" in the search results. And I had changed srch-Description2 in the code XSLT (I modified in the web part Search result)

The productiondescription shows the first 3 lines in the search results (works well), but the more/less does not work. If I click on More>>, nothing appears. And the rest productiondescription cannot display.

I am sure that my JavaScript code is not right. I had tried other methodes, but nothing works. Here is my code

<div class="srch-Description2">

      <xsl:when test="string-length($productiondescription) &lt; 400">
  <div id="itemdescription">
          <xsl:value-of select="$productiondescription" />
      <div id="itemdescriptionless">
          <xsl:value-of select="substring($productiondescription,1,400)" />
        <a href="#" onclick="javascript:moreless(this,'{productiondescription}')">more&gt;&gt;</a>

<script type="text/javascript">
    function moreless(abc,fullText)
      if(abc.innerText == "more&gt;&gt;")
      div = abc.parentNode.getElementsByTagName('div');
      div[0].innerText = fullText;
      abc.innerText = "&lt;&lt;less";
      else if(abc.innerText == "&lt;&lt;less")
      div = abc.parentNode.getElementsByTagName('div');
      div[0].innerText = fullText.substring(0,400);
      abc.innerText = "more&gt;&gt;";
</div >    

I found the answer:

First, javascript:moreless(this,'{productiondescription}') does not work, I delete '{productiondescription}'

Second, I delete fullText in function moreless(abc,fullText)

Third, I add full description and short description to XSLT, and then I add the following code to JS and hide full description. I know it is not a good idea but I cannot find another one

 var fulldescriptions = document.getElementById("fullproductiondescription").innerHTML;     

Fourth, I change abc.innerText to abc.innerHTML, and it works well !!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.