6 Replies Latest reply on Apr 27, 2009 10:19 PM by db_tw

    Creating button that prints DHTML drop-down text

    db_tw

      Hi -- I'm trying to follow instructions in Rick Stone's Tips 'n Tricks (Thank you so much Rick!) for creating a Print button that when clicked, expands all DHTML drop-downs in the topic and then prints the topic. However, I'm just learning RH7 and don't know JavaScript. The button appears on the page, but when clicked doesn't do anything. If anyone out there does know JavaScript and can tell me what I'm doing wrong, I'd greatly appreciate it!

       

      I copied Rick's code into the topic HEAD:

       

      <script type="text/javascript" language=JavaScript1.2><!--
      var arrayofDivs = document.all.tags("DIV");
      }
      function showEm() { for (x=0;x<arrayofDivs.length;x++) { arrayofDivs[x].style.display = "block"; }
      }
      function hideEm() { for (x=0;x<arrayofDivs.length;x++) { arrayofDivs[x].style.display = "none"; }
      }
      function printEm() { ;showEm();setTimeout('window.print()',50)}
      //--></script>

       

      <input type=button name=button value="Print this topic" onClick="JavaScript:printEm()">

        • 1. Re: Creating button that prints DHTML drop-down text
          Gravenstein Level 2

          Hi db_tw -

           

          On the third line of the script, there's an end brace that looks like it doesn't belong (no open brace). Try removing that } character on the third line.

           

          HTH,

          G

          • 2. Re: Creating button that prints DHTML drop-down text
            db_tw Level 1

            Hi -- I removed the } but unfortunately, it didn't do anything. Button still doesn't work. Thanks so much for your input though!

            • 3. Re: Creating button that prints DHTML drop-down text
              MergeThis Level 4

              Try deleting the hard carriage return at the end of the first line.

               

               

              Good luck,

              Leon

              • 4. Re: Creating button that prints DHTML drop-down text
                db_tw Level 1

                Hi Leon,

                 

                Thank you so much for your suggestion. No luck though. Maybe I'll have to give up on this feature, or at least try to start learning JavaScript!

                 

                Best,

                Daryl

                • 5. Re: Creating button that prints DHTML drop-down text
                  Gravenstein Level 2

                  FYI, the script did work for me (once I removed that "}" character). Here's some more info, in case it helps.

                   

                  I added Rick's code as specified above. Note that once it was added, then RH does things to it. See below for what my example topic looked like after I did a save. In particular, note how RH assigns an id (a1) to the function in the script, and then later refers to it. Does your topic do that? If not, then that may be where your problem lies. This is from RH8, but the concept should be the same.

                   

                  G

                   

                   

                  <?xml version="1.0" encoding="utf-8" ?>
                  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                  <html xmlns="http://www.w3.org/1999/xhtml">
                  <head>
                  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                  <meta name="generator" content="Adobe RoboHelp 8" />
                  <title>test1</title>
                  <script type="text/javascript" language="JavaScript1.2">//<![CDATA[
                  <!--
                  var arrayofDivs = document.all.tags("DIV");

                  function showEm() { for (x=0;x<arrayofDivs.length;x++) { arrayofDivs[x].style.display = "block"; }
                  }
                  function hideEm() { for (x=0;x<arrayofDivs.length;x++) { arrayofDivs[x].style.display = "none"; }
                  }
                  function printEm() { ;showEm();setTimeout('window.print()',50)}
                  //-->
                  //]]></script>
                  <?rh-script_start ?><script type="text/javascript" language="JavaScript1.2">//<![CDATA[
                  if( typeof( TextPopupInit ) != 'function' ) TextPopupInit = new Function();
                  TextPopupInit('a1', 'POPUP285400662');
                  //]]></script><?rh-script_end ?>
                  </head>

                  <body>
                  <?rh-script_start ?><script src="../ehlpdhtm.js" type="text/javascript"
                          language="JavaScript1.2"></script><?rh-script_end ?>
                  <h1>test1</h1>
                  <p>Type topic text <a class="dropspot" href="javascript:TextPopup(this)"
                         id="a1">here</a>.</p>
                  <div class="droptext" id="POPUP285400662" style="display: none;">
                  <p>Some lovely dropdown text.</p>
                  </div>
                  <p>&#160;</p>
                  <input type="button" name="button" value="Print this topic" onclick="JavaScript:printEm()" />

                  </body>
                  </html>

                  • 6. Re: Creating button that prints DHTML drop-down text
                    db_tw Level 1

                    Hi G -- Thanks so much for your help! I have RH7 from the TCS. I did a Test topic with one drop-down, removed the } and saved, but it still doesn't work. In the RH script that RH inserts in mine, I don't see the a1 reference that's in yours: TextPopupInit('a1', 'POPUP285400662');  however, it does put id=a1 in the drop-down code (without quotes around a1).  Also, in yours, on the first line after the JavaScript declaration there is //<![CDATA[  (plus the closing code for it at the end of course), which doesn't appear in mine.

                    I'm just learning RH7 and don't know JS, so I'm giving up on having this function. However, being one of those people who hates to not understand why something doesn't work, do you have any idea why RH isn't inserting the a1 reference in the RH script?

                    Thanks so much!
                    Daryl

                    Here's what my test shows:

                    <!doctype HTML public "-//W3C//DTD HTML 4.0 Frameset//EN"> <html><head>
                    <meta http-equiv=content-type content="text/html; charset=utf-8">
                    <meta name=generator content="Adobe RoboHelp - www.adobe.com">
                    <meta name=generator-major-version content=0.1>
                    <meta name=generator-minor-version content=1>
                    <meta name=filetype content=RoboHelp>
                    <meta name=filetype-version content=1>
                    <meta name=page-count content=1>
                    <meta name=layout-height content=604>
                    <meta name=layout-width content=1104> <title>test</title> <link rel=StyleSheet href=ContractWorks.css>

                    <script type="text/javascript" language=JavaScript1.2><!-- var arrayofDivs = document.all.tags("DIV"); function showEm() { for (x=0;x<arrayofDivs.length;x++) { arrayofDivs[x].style.display = "block"; }
                    }
                    function hideEm() { for (x=0;x<arrayofDivs.length;x++) { arrayofDivs[x].style.display = "none"; }
                    }
                    function printEm() { ;showEm();setTimeout('window.print()',50)}</script>
                    </head>

                    <body>
                    <robohelp><script type="text/javascript" language=JavaScript1.2 x-save-method=compute-relative  src="ehlpdhtm.js"></script> <script type="text/javascript" language=JavaScript1.2>
                    <!--
                    if( typeof( FilePopupInit ) != 'function' ) FilePopupInit = new Function();if( typeof( TextPopupInit ) != 'function' ) TextPopupInit = new Function();  //--> </script> </robohelp> <robohelp><form> </robohelp> <div class=x-popup-text id=POPUP312934890 style='display: none; position: absolute' > <p>Here's the text for the drop-down.</p> </div> <h1>Test</h1> <p>This is my <a class=dropspot x-use-popup=#POPUP312934890 x-popup-type=pulldown  href="javascript:TextPopup(this)" id=a1>drop-down</a><robohelp><script
                    type="text/javascript" language=JavaScript1.2><!-- TextPopupInit('a1'); //--></script></robohelp>.</p> <p> </p> <p><input type=button name=button value="Print this topic" onClick="JavaScript:printEm()"></p>
                    <p> </p>
                    </body>
                    </html>