473,569 Members | 2,700 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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!
Jul 23 '05 #1
4 1771
On 20 Jul 2004 09:58:00 -0700, Jeremy wrote:
<script language="JavaS cript">
var ln1 = "<!--#include file='incfile.i nc'-->";


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
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="JavaS cript">
<script type="text/javascript">

var ln1 = "<!--#include file='incfile.i nc'-->";
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:Res ponse.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="morebutt on"
onClick="locati on.href='incfil e.htm';">&gt;&g t;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.

--
Grant Wagner <gw*****@agrico reunited.com>
comp.lang.javas cript 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="JavaS cript">
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.i nc'-->";
var ln2 = ln1.slice(0,20) ;
You could write

var ln1 = "<!--#include file='incfile.i nc'-->".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:Res ponse.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="morebutt on"
onClick="locati on.href='incfil e.htm';">&gt;&g t;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
<http://validator.w3.or g/>.
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*********@we b.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.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.
Jul 23 '05 #5

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

Similar topics

4
21953
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 truncateCharArray(int maxLength , char * buffer ) { if ((0 == buffer) || !(0 < maxLength)) return; if (maxLength < strlen(buffer))
5
2499
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 very carefully define the order in which paths are searched with command line options on the compiler. Both can cause problems, especially when...
5
5420
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 suggestions are appreciated. I am BEGINNER TO C PROGRAAMING. Thanks
1
2511
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 was: Import Namespace="System.Web.Mail" Dim aa as new StringBuilder(600010) Dim i as Integer
6
2106
by: tshad | last post by:
In my User control, I tried to do this: *************************************************************************** <Script runat="server"> Public ClientName As String = "<!-- #include file = ...\includes\StaffingHeaders.inc -->" </Script> <%=ClientName%> ****************************************************************************
17
11813
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 I force Access not to truncate?! Thanx, /Toommy
5
2603
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 ideas on how to go about this? It's a strange requirement for a program but i can't get around it. Thanks.
4
7754
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 way floating points work. double TruncateToDigits(double dValue, int iDigitsToRightOfDecimal) { double dEpsilon = 1e-8; // high limit, about...
15
5196
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 execute the SQL code. Here's the corresponding snippets: 'declare variables: Dim strProc As String
0
7698
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8122
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7673
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7970
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6284
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5513
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...

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.