truncating include file as string problem

J

Jeremy

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="JavaScript">
var ln1 = "<!--#include file='incfile.inc'-->";
var ln2 = ln1.slice(0,20);
</script>
</head>
<html>
<BODY>
<b>Latest News</b><font size=1>

<javascript:Response.write(ln2);>
</font><span class="morebutton"
onClick="location.href='incfile.htm';">&gt;&gt;MORE</span>

</BODY>
</HTML>


Any ideas???

Thanks in advance!
 
G

Grant Wagner

Jeremy said:
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="JavaScript">

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

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

<url:
http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/string.html#1194618
/>
<url:
http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/string.html#1194665
/>
<url:
http://msdn.microsoft.com/library/en-us/jscript7/html/jsmthsubstr.asp />
<url:
http://msdn.microsoft.com/library/en-us/jscript7/html/jsmthsubstring.asp
/>

</script>
</head>
<html>
<BODY>
<b>Latest News</b><font size=1>

<javascript:Response.write(ln2);>

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.
</font><span class="morebutton"
onClick="location.href='incfile.htm';">&gt;&gt;MORE</span>

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".
</BODY>
</HTML>

Any ideas???

Thanks in advance!

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.
 
T

Thomas 'PointedEars' Lahn

Jeremy said:
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="JavaScript">

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.
var ln1 = "<!--#include file='incfile.inc'-->";
var ln2 = ln1.slice(0,20);

You could write

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

and avoid one more global.
</script>
</head>
<html>
<BODY>
<b>Latest News</b>

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.
<font size=1>

<javascript:Response.write(ln2);>

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

document.write(ln2);

but ... (see above/below)

Do not use "font" elements anymore. They have been deprecated in
favor of CSS with the HTML 4.01 Specification as of December 1999.
<span class="morebutton"
onClick="location.href='incfile.htm';">&gt;&gt;MORE</span>

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*?
</BODY>
</HTML>


Any ideas???

You should repair your Question Mark key and use
Thanks in advance!

You're welcome.


PointedEars
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated Mon, 26 Jul
2004 02:58:53, seen in Thomas 'PointedEars'
Lahn said:
Do not use "font" elements anymore. They have been deprecated in
favor of CSS with the HTML 4.01 Specification as of December 1999.


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

Don't be intolerant.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top