LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-29-2007, 03:00 PM   #1
Kamikazee
Member
 
Registered: May 2005
Location: Aus
Distribution: SimplyMEPIS 3.3
Posts: 107

Rep: Reputation: 15
JavaScript - document.getElementsById


Hey, I've got some code to hide/show a comment box. However for some reason it will not work using 'document.getElementsById()'...

The JavaScript
Code:
	function display(id){
		var span = document.getElementsById(id);
		for (i = 0; i < span.length; i++) {
			if (span[i].style.display=='none'){
				span[i].style.display='inline';
			} else {
				span[i].style.display='none';
			}
		}
	}

The html on the page - I'm using a templating engine so hence ID will be different for every comment box on the page.
Code:
	<p class="comment"><a href="#" onClick="JavaScript:display({docs.U_DOCID})">Make a comment</a> | 
	<a href="document.php?mode=view&d={docs.U_DOCID}">{docs.U_COMMENTS}</a></p>

		<span style="display:none" id="{docs.U_DOCID}">
		<!-- A FORM -->
		</span>

The onCLick works if i change the JavaScript to byElementsByTag("span") but that affects all the spans, not just the one.

Any help?
 
Old 10-29-2007, 04:00 PM   #2
rednuht
Member
 
Registered: Aug 2005
Posts: 239
Blog Entries: 1

Rep: Reputation: 31
have you got the pure html it produces, I would like to see the exact {docs.U_DOCID}
Interestingly the example
Code:
onClick="javascript:display({docs.U_DOCID})"
does not make use of single quotes to encase the {docs.U_DOCID} (result of)
 
Old 10-29-2007, 04:23 PM   #3
Kamikazee
Member
 
Registered: May 2005
Location: Aus
Distribution: SimplyMEPIS 3.3
Posts: 107

Original Poster
Rep: Reputation: 15
Here is the html that is produced.

Code:
<p class="comment"><a href="#" onClick="JavaScript:display(16)">Make a comment</a> | 
<a href="document.php?mode=view&d=16">0 comments</a></p>

<span style="display:none" id="16">
<!-- table -->
</span>
I also tried enclosing {docs.U_DOCID} with single quotes to produce the code below but it had no effect.
Code:
<p class="comment"><a href="#" onClick="JavaScript:display('16')">Make a comment</a>
I output'd 'id' from the js and it gives me the correct id. Which makes me assume its the script.

Code:
function display(id){
	var span = document.getElementsById(id);
	for (i = 0; i < span.length; i++) {
		if (span[i].style.display=='none'){
			span[i].style.display='inline';
		} else {
			span[i].style.display='none';
		}
	}
}

Last edited by Kamikazee; 10-30-2007 at 03:17 AM.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
javascript document.links always is cero poeta_boy Programming 1 11-23-2006 10:30 AM
Ubuntu Edgy/Firefox 2/Javascript - Firefox closes accessing websites with Javascript Interdictor Ubuntu 8 11-02-2006 11:58 AM
JavaScript question - how to save a created document within browser davidnye Programming 1 09-05-2006 11:36 AM
how do i create a document, then a directory and save the document in it. jtdodge Linux - Newbie 9 06-15-2005 11:03 AM
Convert openoffice document into ms document through cli? bruno buys Linux - Software 0 07-05-2004 09:59 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:14 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration