/    Sign up×
Community /Pin to ProfileBookmark

show all info on "read more" return to normal size on "view less"

Hi, I will just like to say that this site has already been a help and thanks a lot for the help on my previous question. However, I have one more feature I been trying to accomplish but haven’t been successful in my research. What I want to do is I have a lengthy paragraph and I’m only displaying the first 200 characters in the paragraph then i have a “read more” when the “read more” is clicked I want all the information from the paragraph to be displayed and then have a “view less” link and when the “view less” link is clicked for it to go back to only displaying the first 200 characters. This seems to be quite difficult to find out how to do, does anyone know how to do this? thanks in advance for any help anyone might be willing to give me.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@so_is_thisDec 14.2006 — Here is a simplistic approach to the issue:
[code=html]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Read More/Less</title>
<style type="text/css">
<!--
a {
text-decoration: none;
}
td, th {
padding: 0px 10px;
}
-->
</style>
<script type="text/javascript">
<!--//
var shortTextLength = 200;
var saveLargeText = '';
function MoreOrLess(link, span)
{
var obj = document.getElementById(span);
if(saveLargeText == '')
{
saveLargeText = obj.firstChild.data;
obj.firstChild.data = saveLargeText.substr(0, shortTextLength);
link.firstChild.data = "...more...";
}
else
{
obj.firstChild.data = saveLargeText;
saveLargeText = '';
link.firstChild.data = "less";
}
link.blur();
return false;
}
//-->
</script>
</head>

<body>
<table width="700">
<tr>
<td nowrap>Column 1</td>
<td nowrap>Column 2</td>
<td nowrap>Column 3</td>
</tr>
<tr>
<td nowrap>Testing ==></td>
<td><span id="largeText">
Now is the time for all young men to come to the aid of their country.&nbsp;
The quick brown fox jumped over the lazy dog.&nbsp;
Now is the time for all young men to come to the aid of their country.&nbsp;
The quick brown fox jumped over the lazy dog.&nbsp;
Now is the time for all young men to come to the aid of their country.&nbsp;
The quick brown fox jumped over the lazy dog.&nbsp;
Now is the time for all young men to come to the aid of their country.&nbsp;
The quick brown fox jumped over the lazy dog.&nbsp;
Now is the time for all young men to come to the aid of their country.&nbsp;
The quick brown fox jumped over the lazy dog.&nbsp;
Now is the time for all young men to come to the aid of their country.&nbsp;
The quick brown fox jumped over the lazy dog.&nbsp;
Now is the time for all young men to come to the aid of their country.&nbsp;
The quick brown fox jumped over the lazy dog.&nbsp;
Now is the time for all young men to come to the aid of their country.&nbsp;
The quick brown fox jumped over the lazy dog.&nbsp;
Now is the time for all young men to come to the aid of their country.&nbsp;
The quick brown fox jumped over the lazy dog.&nbsp;
Now is the time for all young men to come to the aid of their country.&nbsp;
The quick brown fox jumped over the lazy dog.</span>

<script type="text/javascript"><!--//
var str = '&nbsp; [<a id="ctlMoreOrLess" href="javascript:void(0)"';
str += ' onclick="return MoreOrLess(this, 'largeText')">less</a>]';
document.write(str);
MoreOrLess(document.getElementById('ctlMoreOrLess'), 'largeText');
//--></script>

</td>
<td nowrap><== Testing</td>
</tr>
</table>
</body>
</html>[/code]
Copy linkTweet thisAlerts:
@newjersey_cfmauthorDec 14.2006 — your a genius its work perfectly, now if only i understood what those tags meant ill be in great shape lol does anyone know of a site where i could look up javascript tags(not sure if this site does that) for example i have no clue what var str= means or str += means.. the problem is im really new to javascript, i use a lot of coldfusion when i have to program im starting to like javascript and want to start using javascript in place of coldfusion whenever i could. thanks for the help...
Copy linkTweet thisAlerts:
@so_is_thisDec 14.2006 — [B]var [/B] is the operator for creating a variable.

[B]+= [/B] is the operator for concatenating or adding the information on the right to the variable content given on the left.
×

Success!

Help @newjersey_cfm spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...