PDA

View Full Version : Generic code for "click to view more text" item?



jump
Mar 4th, 2013, 01:17 AM
Hi guys,

I am looking for a generic code where I can type text and then have have a clickable sentence (or phrase) that says "click to view more" and then have the content expand. A website with a generator would also be great.

Thank you in advance!

VIPStephan
Mar 4th, 2013, 11:23 AM
No, my friend, web development is nothing for lazy people. You need to do a little more than that. And after all, dynamically expandable content can only be done with JavaScript.

Philip M
Mar 4th, 2013, 11:50 AM
Use the search feature of the forum, for example

http://www.codingforums.com/showthread.php?t=147863

Another example:-


<html>
<head>
</head>

<body onload = "toggleTxt()">

<div id = "theText"></div>
<p id = "but1" style = "color:red; font-family:Arial; font-size:10pt; position:absolute; right:95px"; onclick = "toggleTxt()">View More [+]</p>

<script type = "text/javascript">

var tflag = 0;
function toggleTxt() {
var txt = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris blandit erat sed enim convallis tincidunt. Vivamus vestibulum hendrerit blandit. Donec sagittis magna justo. Sed vehicula auctor mauris quis dictum. Aliquam erat volutpat. Phasellus at quam nibh, sed dictum neque. Maecenas lectus arcu, sagittis quis dapibus sed, lobortis id velit. Vestibulum ut tortor neque. Quisque porttitor ornare massa sit amet ornare. Vivamus arcu augue, fringilla in adipiscing eget, viverra sit amet purus. Praesent euismod, velit ac aliquet elementum, velit lectus laoreet magna, vel auctor diam libero non turpis. Fusce eu sapien in enim dapibus iaculis. Cras et molestie orci. Sed nec est elit, eu suscipit quam." + "<br><br>" +
"Phasellus accumsan aliquam quam, vitae fermentum purus pellentesque quis. Aliquam viverra lacus at tortor scelerisque vestibulum eget vitae orci. Etiam volutpat neque non erat facilisis egestas. Duis vulputate lacus eget nulla mattis vulputate. Fusce vehicula libero dolor, vitae tempor nulla. Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium. "

if (tflag == 0) {
document.getElementById("theText").innerHTML = txt.substring(0,399) + "......";
tflag = 1;
document.getElementById("but1").innerHTML = "View More [+]";
}
else {
document.getElementById("theText").innerHTML = txt;
document.getElementById("but1").innerHTML = "View Less [-]";
tflag = 0;
}
}
</script>

</body>
</html>

Or are you looking for an expandable textarea?



Special Offer - 4 Toilet Rolls only 1.45 (34p per 100 shts). - Tesco

Old Pedant
Mar 4th, 2013, 09:17 PM
Special Offer - 4 Toilet Rolls only 1.45 (34p per 100 shts). - Tesco

Does that include shipping?