Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cant Change DIV innerhtml! Help 4

Status
Not open for further replies.

countdrak

Programmer
Jun 20, 2003
358
US
So I am using simple toggle function. To display text when a link is clicked. I am doing it over a class name because the divs are generated dynamically in a query.

What I want to do is change the "Display Text" to "Close Text" but I cant seem to get it to work.

Here is my js

Code:
<script>
var allPageTags = new Array(); 

function toggle(theClass,x) 
{
	var allPageTags=document.getElementsByTagName("*");


	for (i=0; i<allPageTags.length; i++) 
	{
		if (allPageTags[i].className==theClass) 
		{
 			if( allPageTags[i].style.display=='none' )
			{
   			allPageTags[i].style.display = '';
			d = "document.getElementById(\'"+x+"\').innerHTML";
			//alert(document.getElementById('LText1').innerHTML);
			alert(d);
			d = 'Close Text';
 			}
		else{
  			 allPageTags[i].style.display = 'none';
 			}
		}
	}
	

	
} 
</script>

Here is the line where I am calling it.

Code:
<A href="javascript:toggle('inviclass#query.CurrentRow#','LText#query.CurrentRow#');"><div id='LText#query.CurrentRow#'>Display Text</div></A>


I am dynamically generating div and class ids using a query . When I click display text the toggle works fine. I can see the correct paragraph open , but the text does not change to "Close text
 
At the moment, all this is doing is copying a string into d.
Code:
            d = "document.getElementById(\'"+x+"\').innerHTML";
            //alert(document.getElementById('LText1').innerHTML);
            alert(d);
            d = 'Close Text';
you should assign the element to d and then write to the innerHTML tag:
Code:
            d = document.getElementById(x);
            d.innerHTML = 'Close Text';
 
Thanks a ton ..I have no clue why I was trying to create the string. :)
 
countdrak, why don't you give starsky51 a star for the time and effort they put in to debug your problem?

Your profile shows that you've asked 168 questions on this forum, but only given out a star 15 times. The fact that you've given out any stars at all shows that you're aware of the system.

Surely the 153 times that you didn't give out stars, you were still given helpful advice, yes? It only takes 2 seconds and is a small price to pay for free consulting.

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson

[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top