473,324 Members | 2,179 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

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="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;MOR E</span>

</BODY>
</HTML>
Any ideas???

Thanks in advance!
Jul 23 '05 #1
4 1759
On 20 Jul 2004 09:58:00 -0700, Jeremy wrote:
<script language="JavaScript">
var ln1 = "<!--#include file='incfile.inc'-->";


Is this server-side Javascript?

You cannot include files using client-side JS.

[ ..and the 'language="JavaScript"'
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
Jul 23 '05 #2
Jeremy wrote:
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">
<script type="text/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/...g.html#1194618
/>
<url:
http://devedge.netscape.com/library/...g.html#1194665
/>
<url:
http://msdn.microsoft.com/library/en...smthsubstr.asp />
<url:
http://msdn.microsoft.com/library/en...hsubstring.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;MOR E</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.

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #3
Jeremy wrote:
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)
</font>
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;MOR E</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
<http://validator.w3.org/>.
Thanks in advance!


You're welcome.
PointedEars
Jul 23 '05 #4
JRS: In article <41**************@PointedEars.de>, dated Mon, 26 Jul
2004 02:58:53, seen in news:comp.lang.javascript, Thomas 'PointedEars'
Lahn <Po*********@web.de> posted :
<font size=1> </font>


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.

--
© 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.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: qazmlp | last post by:
Can anybody comment(& suggest improvements) on the following implementation that is for truncating the character buffer contents to the desired length? Truncating char array void...
5
by: David Mathog | last post by:
One thing that can make porting C code from one platform to another miserable is #include. In particular, the need to either place the path to an included file within the #include statement or to...
5
by: VISHNU VARDHAN REDDY UNDYALA | last post by:
Hello, Can someone over here help me in truncating a float variable. I mean if PI=3.14159 ...How can I get to read the first two or first three decimal values with out rounding them. Any...
1
by: Jitesh Sinha | last post by:
Hi, I am running Windows 2003/ IIS 6.0. I was stuck with rather a abnormal behaviour of System.Web.mail class. It was truncating the message body after 3,071 character. The code i was testing...
6
by: tshad | last post by:
In my User control, I tried to do this: *************************************************************************** <Script runat="server"> Public ClientName As String = "<!-- #include file =...
17
by: tommy | last post by:
Hi all, I' m adding strings to some fields in my table via Access. The strings sometimes have trailing spaces and I really need to have it that way, but Access truncates trailing spaces. How can...
5
by: Alex Leach | last post by:
I need to check whether a string of letters contains any numbers at the end of the string, and if so, remove all numbers. There won't ever be numbers at the beginning or middle of the string. Any...
4
by: Todd | last post by:
I have a function that takes a double and truncates it to a specified number of decimal places. I've found that I have to add a small number to the input value otherwise I get errors due to the...
15
geolemon
by: geolemon | last post by:
I'm having a seriously Twilight Zone moment: In the code below, I'm building a SQL command into a string variable, declared at the top of my code. Then, I connect to the database and try to...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.