truncating include file as string problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jeremy

    truncating include file as string problem

    I have an include file which has some text such as:

    The quick brown fox jumped over the lazy dog

    I want to have a certain amount of that text to display on one page
    wherein the user can click a link for more of the text on a new page
    such as:

    The quick brown fox >>MORE

    unfortunately, I'm having trouble making that work. Here is my code:

    <head>
    <script language="JavaS cript">
    var ln1 = "<!--#include file='incfile.i nc'-->";
    var ln2 = ln1.slice(0,20) ;
    </script>
    </head>
    <html>
    <BODY>
    <b>Latest News</b><font size=1>

    <javascript:Res ponse.write(ln2 );>
    </font><span class="morebutt on"
    onClick="locati on.href='incfil e.htm';">&gt;&g t;MORE</span>

    </BODY>
    </HTML>


    Any ideas???

    Thanks in advance!
  • Andrew Thompson

    #2
    Re: truncating include file as string problem

    On 20 Jul 2004 09:58:00 -0700, Jeremy wrote:
    [color=blue]
    > <script language="JavaS cript">
    > var ln1 = "<!--#include file='incfile.i nc'-->";[/color]

    Is this server-side Javascript?

    You cannot include files using client-side JS.

    [ ..and the 'language="Java Script"'
    should read 'type="text/javascript"' ]

    --
    Andrew Thompson
    http://www.PhySci.org/ Open-source software suite
    http://www.PhySci.org/codes/ Web & IT Help
    http://www.1point1C.org/ Science & Technology

    Comment

    • Grant Wagner

      #3
      Re: truncating include file as string problem

      Jeremy wrote:
      [color=blue]
      > I have an include file which has some text such as:
      >
      > The quick brown fox jumped over the lazy dog
      >
      > I want to have a certain amount of that text to display on one page
      > wherein the user can click a link for more of the text on a new page
      > such as:
      >
      > The quick brown fox >>MORE
      >
      > unfortunately, I'm having trouble making that work. Here is my code:
      >
      > <head>
      > <script language="JavaS cript">[/color]

      <script type="text/javascript">
      [color=blue]
      >
      > var ln1 = "<!--#include file='incfile.i nc'-->";
      > var ln2 = ln1.slice(0,20) ;[/color]

      slice() is a method of an array, not a string. You probably want
      substring() or substr():

      <url:

      />
      <url:

      />
      <url:
      http://msdn.microsoft.com/library/en...smthsubstr.asp />
      <url:
      Find official documentation, practical know-how, and expert guidance for builders working and troubleshooting in Microsoft products.

      />

      [color=blue]
      > </script>
      > </head>
      > <html>
      > <BODY>
      > <b>Latest News</b><font size=1>
      >
      > <javascript:Res ponse.write(ln2 );>[/color]

      I have no idea what this is. It looks like a combination of server and
      client-side code, but it is mostly just wrong.

      Presumably you want:

      <script type="text/javascript">
      document.write( ln2);
      </script>

      Embedded <script ...> tags inside <font ...> tags (which you shouldn't be
      using anyway) may not work in some user agents. You'd be better off to
      use a span with a class attached.
      [color=blue]
      > </font><span class="morebutt on"
      > onClick="locati on.href='incfil e.htm';">&gt;&g t;MORE</span>[/color]

      You're using a <span> to mimic an <a> because... you don't want it to
      work if people don't have Javascript enabled in their browser? or you
      don't want it to work if their browser doesn't comprehend the onclick
      event on a <span>?

      You also don't appear to be making any decision about whether the entire
      content of ln1 was actually displayed. As a result, the MORE <span> (I
      hesitate to call it a link) appears even if ln1 consists of the word
      "Hello".
      [color=blue]
      > </BODY>
      > </HTML>
      >
      > Any ideas???
      >
      > Thanks in advance![/color]

      Programming is not a hit-or-miss guessing game. You have to understand
      the concepts, understand the language you are working in, and, when
      necessary, consult the documentation to achieve the desired goal.

      --
      Grant Wagner <gwagner@agrico reunited.com>
      comp.lang.javas cript FAQ - http://jibbering.com/faq


      Comment

      • Thomas 'PointedEars' Lahn

        #4
        Re: truncating include file as string problem

        Jeremy wrote:[color=blue]
        > I have an include file which has some text such as:
        >
        > The quick brown fox jumped over the lazy dog
        >
        > I want to have a certain amount of that text to display on one page
        > wherein the user can click a link for more of the text on a new page
        > such as:
        >
        > The quick brown fox >>MORE
        >
        > unfortunately, I'm having trouble making that work. Here is my code:
        >
        > <head>
        > <script language="JavaS cript">[/color]

        It should be

        <script type="text/javascript">

        but client-side scripting only is not a reasonable solution on an Internet
        site (and sometimes not even in an Intranet). Do it server-side, with PHP,
        Perl, ASP and the like.
        [color=blue]
        > var ln1 = "<!--#include file='incfile.i nc'-->";
        > var ln2 = ln1.slice(0,20) ;[/color]

        You could write

        var ln1 = "<!--#include file='incfile.i nc'-->".slice(0, 20);

        and avoid one more global.
        [color=blue]
        > </script>
        > </head>
        > <html>
        > <BODY>
        > <b>Latest News</b>[/color]

        If this should be a heading, make it one:

        <h1>Latest News</h1>

        If you do not like the style, use CSS to format the element.
        [color=blue]
        > <font size=1>
        >
        > <javascript:Res ponse.write(ln2 );>[/color]

        What is this nonsense supposed to do? Maybe you are looking for

        document.write( ln2);

        but ... (see above/below)
        [color=blue]
        > </font>[/color]

        Do not use "font" elements anymore. They have been deprecated in
        favor of CSS with the HTML 4.01 Specification as of December 1999.
        [color=blue]
        > <span class="morebutt on"
        > onClick="locati on.href='incfil e.htm';">&gt;&g t;MORE</span>[/color]

        So you already know about CSS? But obviously you do not know
        that not all users have software with support for client-side
        scripting. And those who have, have often disabled it.
        Abusing the "span" element to work like a link (a[href]) is
        foolishness. Or have you used a structure editor without
        minimum clue about HTML/CSS/J(ava)Script to "achieve" *this*?
        [color=blue]
        > </BODY>
        > </HTML>
        >
        >
        > Any ideas???[/color]

        You should repair your Question Mark key and use
        <http://validator.w3.or g/>.
        [color=blue]
        > Thanks in advance![/color]

        You're welcome.


        PointedEars

        Comment

        • Dr John Stockton

          #5
          Re: truncating include file as string problem

          JRS: In article <4104574D.70009 08@PointedEars. de>, dated Mon, 26 Jul
          2004 02:58:53, seen in news:comp.lang. javascript, Thomas 'PointedEars'
          Lahn <PointedEars@we b.de> posted :[color=blue]
          >[color=green]
          >> <font size=1>[/color][/color]
          [color=blue][color=green]
          >> </font>[/color]
          >
          >Do not use "font" elements anymore. They have been deprecated in
          >favor of CSS with the HTML 4.01 Specification as of December 1999.[/color]


          Font elements are in some circumstances necessary for the support of
          less recent browsers.

          Don't be intolerant.

          --
          © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
          <URL:http://jibbering.com/faq/> JL / RC : FAQ for news:comp.lang. javascript
          <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
          <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

          Comment

          Working...