Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 1st, 2007, 10:06 PM   #1
eyeball_kid
Newbie
 
Join Date: Oct 2007
Posts: 3
Rep Power: 0 eyeball_kid is on a distinguished road
Changing table cell contents using DHTML

Hi. I hope it's not too presumptuous of me to ask for help in just my second post, but I'm having a little problem here and my understanding of the JavaScript DOM is spotty at best.

What I'm trying to do is have a 2-cell horizontally laid out table that functions thus: The left-hand cell contains an unordered list of links and the right cell contains HTML-formatted content consisting of a single image and some wrapped text. Clicking one of a list of hyperlinks in a left-hand table cell triggers changes to the contents of the right-hand cell.

Is there a way to store the HTML for the content cell into a string variable or an array, and then to write the appropriate variable's contents into the right-hand cell when clicking each link? Or maybe just place the html right into the <a> tag for each list item?
eyeball_kid is offline   Reply With Quote
Old Oct 2nd, 2007, 12:17 AM   #2
eyeball_kid
Newbie
 
Join Date: Oct 2007
Posts: 3
Rep Power: 0 eyeball_kid is on a distinguished road
OK I got it to work in IE 6 but not in Firefox.

Here's what I've got so far:

<html>

<head>

<title>Stupid bitch-ass page that won't work in Firefox</title>

<script type="text/JavaScript1.2">

var i;

var blurb = new Array()

blurb[0] = "gobbldygook"
blurb[1] = "blahblahblah"
blurb[2] = "some crap"
blurb[3] = "even more crap"
blurb[4] = "yet still more crap"
blurb[5] = "damn this smells really bad"
blurb[6] = "can't think of anything better to write here"
blurb[7] = "geez this is stupid"
blurb[8] = "I'm tired of typing these dumb blurbs";


function changeContent(i){

document.getElementById("contentcell").innerHTML = blurb[i];
}
	
</script>
</head>

<body>

<table>
<table id="mytable" cellspacing="0" cellpadding="0" border="1" width="100%">
		<tr><td>
			<table border="0" width="100%" id="table1" height="100%" cellspacing="0" cellpadding="0">
			<tbody>
				<tr>
					<td width="230" align="left" valign="top">
					<ul>
					<li><a href="javascript:changeContent('0')">Text sample 1</a></li>
					<li><a href="javascript:changeContent('1')">Text sample 2</a></li>
					<li><a href="javascript:changeContent('2')">Text sample 3</a></li>
					<li><a href="javascript:changeContent('3')">Text sample 4</a></li>
					<li><a href="javascript:changeContent('4')">Text sample 5</a></li>
					<li><a href="javascript:changeContent('5')">Text sample 6</a></li>
					<li><a href="javascript:changeContent('6')">Text sample 7</a></li>
					<li><a href="javascript:changeContent('7')">Text sample 8</a></li>
					<li><a href="javascript:changeContent('8')">Text sample 9</a></li>
					</ul>
					</td>
					</div>
					<td id="contentcell"></td>
				</tr>
			</tbody>
			</table>

</body>

</html>

Last edited by eyeball_kid; Oct 2nd, 2007 at 12:59 AM.
eyeball_kid is offline   Reply With Quote
Old Oct 2nd, 2007, 12:32 AM   #3
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 837
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
Look into DOM manipulation methods. A few you might find useful:

Quote:
document.createElement(string)
document.createTextNode(string)
node.cloneNode(bool)
node.appendChild(node)
node.insertBefore(node, node)
node.removeChild(node)
node.replaceChild(node, node)
This is a short list from the (highly recommended) book Beginning JavaScript with DOM Scripting and Ajax by Christian Heilmann. I posted it because I have yet to find such a concise yet useful list of such functions online.

DOM manipulation can be tricky because some browsers, such as FireFox, insert text nodes between elements while others, such as IE, do not. Utilizing the Firebug plug-in for Firefox will make your life easier.

You might also find this useful.
titaniumdecoy is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[beginner] how to reverse the contents of a table mariogarcia Java 4 Nov 4th, 2005 3:12 AM
text in a table cell glevine JavaScript and Client-Side Browser Scripting 5 Jun 12th, 2005 8:37 AM
check cell one below - if found add to cell above crmpicco Visual Basic 0 May 9th, 2005 6:32 AM
word wrap in a table cell? kerriganm HTML / XHTML / CSS 4 May 6th, 2005 5:38 PM
Change background on a table row (or cell) kurifu Java 2 Jan 11th, 2005 6:38 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:00 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC