Announcement

Collapse
No announcement yet.

Having trouble with JavaScript in Act_SectionLine.html to display certain sections

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Having trouble with JavaScript in Act_SectionLine.html to display certain sections

    I'm using Actinic V7.0.7 with a website based on the Smart theme. My client & I are aware that this issue would easily be resolved by upgrading to Actinic V8, but my client wants me to persevere using V7 first.

    Task: I'm trying to modify Act_SectionLine.html so that it only displays links to sections that do not contain the HTML encoded '<' character.

    Background: This website is massive, & has over 15,000 products in surprisingly few sections. If the products are simply placed in their sections, some contain literally thouasands or products, which doesn't make for quick page load times! All the products are imported from files exported from an Access database. I have therefore made the Access database split the product sections after 50 products, resulting in sections named thus: Games, Games<01>, Toys, Toys<01>, Toys<02> etc. Of these, I only want Games & Toys displayed in the list, with all the sections containing the '<' character not displayed.

    Problem: I have modified the Act_SectionLine.html template (from the Smart theme).

    Here's the original:

    <!-- SectionLine HTML begin -->
    <!-- Insert HTML for the beginning of a section title -->

    <DIV ALIGN="LEFT">

    <TABLE BORDER="0" CELLSPACING="0" CELLPADDING="10">

    <TR>

    <TD ALIGN="LEFT" VALIGN="TOP">
    <A HREF="NETQUOTEVAR:SECTIONLINK">NETQUOTEVAR:SECTIONIMAGE</A>
    </TD>

    <TD ALIGN="LEFT" VALIGN="MIDDLE">
    <A HREF="NETQUOTEVAR:SECTIONLINK"><B>NETQUOTEVAR:SECTIONNAME</B></A>
    <br><span class="actxsmall">NETQUOTEVAR:SECTIONTEXT</span>
    </TD>

    </TR>

    </TABLE>

    </DIV>
    NETQUOTEVAR:NEXT
    <!-- Insert HTML for the end of a section title -->
    <!-- SectionLine HTML end -->


    And here's my new version:

    <!-- SectionLine HTML begin -->
    <!-- Insert HTML for the beginning of a section title -->
    <Script language="javascript">
    if ('NETQUOTEVAR:SECTIONNAME'.indexOf('<')<0){document.write('<DIV ALIGN="LEFT"><TABLE BORDER="0" CELLSPACING="0" CELLPADDING="10"><TR><TD ALIGN="LEFT" VALIGN="TOP"><A HREF="NETQUOTEVAR:SECTIONLINK">NETQUOTEVAR:SECTIONIMAGE</A></TD><TD ALIGN="LEFT" VALIGN="MIDDLE"><A HREF="NETQUOTEVAR:SECTIONLINK"><B>NETQUOTEVAR:SECTIONNAME</B></A><br><span class="actxsmall">NETQUOTEVAR:SECTIONTEXT</span></TD></TR></TABLE></DIV>NETQUOTEVAR:NEXT');}
    </Script>
    <!-- Insert HTML for the end of a section title -->
    <!-- SectionLine HTML end -->


    When I get Actinic do display a preview, I get a JavaScript unterminated string error. When I debug the page in the Microsoft Script Debugger, the last section's script doesn't get finished, with the following missing:

    ');}</Script>


    Having said that, there are actually loads of JavaScript unterminated string constant errors, either one per section displayed, or possibly one per row (of three) section links, though they could all just be complaining about the same unterminated string constant, i.e. the last one. Here's an excerpt from the code seen in the debugger:

    <Script language="javascript">
    if ('GAMES'.indexOf('<')<0){document.write('<DIV ALIGN="LEFT"><TABLE BORDER="0" CELLSPACING="0" CELLPADDING="10"><TR><TD ALIGN="LEFT" VALIGN="TOP"><A HREF="P_Online_Catalogue_GAMES.html"><IMG SRC="../Logo.jpg" ALT="Games" BORDER=0 HEIGHT=75 WIDTH=108 ALIGN="ABSMIDDLE"></A></TD><TD ALIGN="LEFT" VALIGN="MIDDLE"><A HREF="P_Online_Catalogue_GAMES.html"><B>GAMES</B></A><br><span class="actxsmall"></span></TD></TR></TABLE></DIV></TD>
    <TD WIDTH="50%" valign="top">
    ');}
    </Script> <Script language="javascript">
    if ('TOYS'.indexOf('<')<0){document.write('<DIV ALIGN="LEFT"><TABLE BORDER="0" CELLSPACING="0" CELLPADDING="10"><TR><TD ALIGN="LEFT" VALIGN="TOP"><A HREF="P_Online_Catalogue_TOYS.html"><IMG SRC="../Logo.jpg" ALT="BY GENRE" BORDER=0 HEIGHT=75 WIDTH=108 ALIGN="ABSMIDDLE"></A></TD><TD ALIGN="LEFT" VALIGN="MIDDLE"><A HREF="P_Online_Catalogue_TOYS.html"><B>TOYS</B></A><br><span class="actxsmall"></span></TD></TR></TABLE></DIV></TD>
    </TR></TABLE>
    <HR SIZE="1" ALIGN="CENTER" WIDTH="600"> </A> <INPUT TYPE=HIDDEN NAME="SID" VALUE="0">
    <INPUT TYPE=HIDDEN NAME="PAGE" VALUE="PRODUCT">
    <INPUT TYPE=HIDDEN NAME="PAGEFILENAME" VALUE="P_index.asp"> <BR><TABLE WIDTH="500" COLS="3" BORDER="0" CELLPADDING="10" CELLSPACING="0" ALIGN="CENTER"> <Actinic:SECTION BLOB="A0000.cat"/><tr><td colspan="3" valign="top"> <A NAME="a5"><table border="0" width="100%" cellspacing="5" cellpadding="1"><tr><td width="100%">
    </Form>


    I've been through this with Actinic support, & they say what I am trying to do should work fine. However, I suspect they may be a bug in a script somewhere, as they also say that what I have done should work. Finally, they said they don't really provide support for advanced JavaScript cusomisations, which sadly this is.

    So can anyone see what is wrong with, either (i) my JavaScript shown here, or (ii) the scripts built into Actinic?

    #2
    I always escape the strings that are intended to be actually output (ie. not part of the JavaScript syntax), and then use double-quotes are the whole string.

    So:
    document.write('<DIV ALIGN="LEFT"> etc...

    becomes:
    document.write("<DIV ALIGN=\"LEFT\"> etc..

    Alan Compton
    www.greenknightgames.co.uk

    Comment


      #3
      I'll give it a go and let you know if it helps.

      When I first tried it, I had the double quotes in the string fighting with those in the JavaScript, so I used single quotes as a workaround, but let's try it this way.

      Thanks.

      Comment


        #4
        Sadly, the result is the same, well, almost!

        Sadly, the result is the same, although I think the JavaScript error is different - before it said Unterminated String, now it says Identifier Expected.

        I'll post the same excerpt as I did before below:

        <Script language="javascript">
        if ("GAMES".indexOf("<")<0){document.write("<DIV ALIGN=\"LEFT\"><TABLE BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"10\"><TR><TD ALIGN=\"LEFT\" VALIGN=\"TOP\"><A HREF=\"P_Online_Catalogue_GAMES.html\"><IMG SRC="../Logo.jpg" ALT="GAMES" BORDER=0 HEIGHT=75 WIDTH=108 ALIGN="ABSMIDDLE"></A></TD><TD ALIGN=\"LEFT\" VALIGN=\"MIDDLE\"><A HREF=\"P_Online_Catalogue_GAMES.html\"><B>GAMES</B></A><br><span class=\"actxsmall\"></span></TD></TR></TABLE></DIV></TD>
        <TD WIDTH="50%" valign="top">
        ");}
        </Script> <Script language="javascript">
        if ("TOYS".indexOf("<")<0){document.write("<DIV ALIGN=\"LEFT\"><TABLE BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"10\"><TR><TD ALIGN=\"LEFT\" VALIGN=\"TOP\"><A HREF=\"P_Online_Catalogue_TOYS.html\"><IMG SRC="../Logo.jpg" ALT="BY GENRE" BORDER=0 HEIGHT=75 WIDTH=108 ALIGN="ABSMIDDLE"></A></TD><TD ALIGN=\"LEFT\" VALIGN=\"MIDDLE\"><A HREF=\"P_Online_Catalogue_TOYS.html\"><B>BY GENRE</B></A><br><span class=\"actxsmall\"></span></TD></TR></TABLE></DIV></TD>
        </TR></TABLE>
        <HR SIZE="1" ALIGN="CENTER" WIDTH="600"> </A> <INPUT TYPE=HIDDEN NAME="SID" VALUE="0">
        <INPUT TYPE=HIDDEN NAME="PAGE" VALUE="PRODUCT">
        <INPUT TYPE=HIDDEN NAME="PAGEFILENAME" VALUE="P_index.asp"> <BR><TABLE WIDTH="500" COLS="3" BORDER="0" CELLPADDING="10" CELLSPACING="0" ALIGN="CENTER"> <Actinic:SECTION BLOB="A0000.cat"/><tr><td colspan="3" valign="top"> <A NAME="a5"><table border="0" width="100%" cellspacing="5" cellpadding="1"><tr><td width="100%">
        </Form>


        Anyway, other than the error message being slightly different, the result is the same.

        Comment


          #5
          I've just noticed something about the code I've shown

          In my code where it says:

          if ('GAMES'.indexOf('<')<0)


          I actually had the < character encoded like this:

          if ("GAMES".indexOf("&#38;#60;")<0)


          (Blimey, that took a few attempts before it would stop doing the same again!)

          Comment

          Working...
          X