View Single Post
05-20-2008, 10:01 AM
#5
Wildhoney is offline Wildhoney
Wildhoney's Avatar
Status: Request a custom title
Join date: Feb 2006
Location: Nottingham
Expertise:
Software:
 
Posts: 1,648
iTrader: 18 / 95%
 

Wildhoney is on a distinguished road

Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney

  Old

I concur with Garrett in this instance. If it is a simple switch of text then pure Javascript, without Ajax, would more than suffice. If nothing else, it's almost instant, whereas with Ajax there is a natural wait time, albeit half a second. Try the following code I've wrote for you. Nothing like a little Javascript in the morning to give vigour to a sleepy soul!

HTML segment:

Code:
<body onload="TextChange.init();">

	<div id="toggleDefault">
		Small paragraph to be changed.
	</div>
	
	<div id="toggleHidden" style="display: none;">
		Small paragraph to be shown upon click.
	</div>
	
	<br />
	
	<a href="javascript:void(0);" id="toggleLink">Toggle</a>

</body>
Javascript segment:

Code:
<script type="text/javascript">

	var TextChange = 
	{
		init: function()
		{
			TextChange.State = 1;
			TextChange.Default = document.getElementById('toggleDefault');
			TextChange.Hidden = document.getElementById('toggleHidden');
			TextChange.Link = document.getElementById('toggleLink');
			
			TextChange.Link.onclick = function()
			{
				switch(TextChange.State)
				{
					case(1): TextChange.show(); break;
					case(2): TextChange.hide(); break;
				}
			}
		},
		
		show: function()
		{
			TextChange.Default.style.display = 'none';
			TextChange.Hidden.style.display = '';
			
			TextChange.State = 2;
		},
		
		hide: function()
		{
			TextChange.Hidden.style.display = 'none';
			TextChange.Default.style.display = '';
			
			TextChange.State = 1;
		}
	}

</script>