Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Div Display Problem

Reply
Thread Tools

Div Display Problem

 
 
Erik Lautier
Guest
Posts: n/a
 
      11-09-2006
Hi, I'm having trouble making a DIV show up; here's the background:
I'm building a message board system where if the message is more than
100 characters, the link "more" appears after the first 100 characters.
When the user clicks it, the full message replaces the truncated one.
I'm pulling a DIV switch and loading the first (the truncated message)
as display:block and the second (the full message) as display:none.
OnClick, the switch is pulled. This *should* be working but I can't
understand the glitch; when I click on the link, the truncated message
disappears, but it's not being replaced by anything. Could it be
because I'm generating the DIVs dynamically? I'm naming them based on
a message ID from a DataReader, but for testing purposes, I've var'd
the relevant IDs in the code. Any help would be appreciated; I've
copied the Javascript and relevant HTML below. Thanks!

<script language="JavaScript">
var ids=new Array('ids23','ids24');

function switchid(id){
hideallids();
showdiv(id);
}

function hideallids(){
//loop through the array and hide each element by id
for (var i=0;i<ids.length;i++){
hidediv(ids[i]);
}
}

function hidediv(id) {
//safe function to hide an element with a specified id
if (document.getElementById) { // DOM3 = IE5, NS6
document.getElementById(id).style.display = 'none';
}
else {
if (document.layers) { // Netscape 4
document.id.display = 'none';
}
else { // IE 4
document.all.id.style.display = 'none';
}
}
}

function showdiv(id) {
//safe function to show an element with a specified id

if (document.getElementById) { // DOM3 = IE5, NS6
document.getElementById(id).style.display = 'block';
}
else {
if (document.layers) { // Netscape 4
document.id.display = 'block';
}
else { // IE 4
document.all.id.style.display = 'block';
}
}
}
</script>

<tr><td><p class='level1'><img src='images/point.gif' align='left'
border='0'><div id='ids23' style="display:block;">What if I write a
very long reply to this message? Will it return where it should or go
back to the&nbsp;&nbsp;<a
href="javascript:switchid('ids24');">...more</a></div><div id='ids24'
style="display:none;">What if I write a very long reply to this
message? Will it return where it should or go back to the beginning of
the line? Stay tuned for the exciting conclusion!</div></td>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
<div ... /> and <div ...></div> K Viltersten ASP .Net 4 03-31-2009 07:33 PM
Problem nesting a div within a div Leupi HTML 6 02-09-2008 04:01 PM
child div blocks parent div, height problem... HJ HTML 5 09-01-2006 04:37 PM
NS/FF don't change div offsetWidth when div innerHTML is added toand div becomes wider mscir Javascript 3 06-26-2005 04:04 PM
Q: Div A inside Div B is larger than Div B Dwayne Madsen Javascript 1 06-01-2005 03:02 PM



Advertisments