Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Toggle text change on click
Old 06-16-2010, 08:12 PM Toggle text change on click
lothop's Avatar
Ultra Talker

Posts: 303
Trades: 0
Hey there, I have a Dynamic Collapsing Box which is toggled by

<div align="right" style="padding-right:25px"><a href="javascript:animatedcollapse.toggle('test1')" >Hide this deal</a></div>

I was wondering how I could make it so that when people click on hide, it changes the text to " Show this deal " and then back to Hide when they click show.

Cheers
__________________
Websites Created;
warscope.com
ratepayers.org.nz
lothop is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-17-2010, 07:30 AM Re: Toggle text change on click
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,384
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
http://www.modtalk.co.uk/_site/code/.../text-element/

I should really get around to documenting the code
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 06-18-2010, 06:20 PM Re: Toggle text change on click
lothop's Avatar
Ultra Talker

Posts: 303
Trades: 0
Quote:
Originally Posted by chrishirst View Post
http://www.modtalk.co.uk/_site/code/.../text-element/

I should really get around to documenting the code
Thats exactly what I need to do. Except without the <div id="h0" style="visibility:hidden;display:none"> This is normally hidden</div>

So it looks like this
HTML Code:
<span id="t0" onclick="toggle('h0',this.id);"><a href="javascript:animatedcollapse.toggle('test1')">Hide this deal</a></span>
<div id="h0" style="visibility:hidden;display:none"></div> 

 
<script type=text/javascript> 
function toggle(id,sender){
	var e = document.getElementById(id).style;
	var t = document.getElementById(sender);
	var disp = e.display;
	var vis = e.visibility;
    var txt = t.innerHTML;
	switch(disp) 
		{
		case 'none':
			disp = 'block';
			vis =  'visible';
            txt = '<a href="javascript:animatedcollapse.toggle(\'test1\')">Show this Deal</a>';
            
			break;
		case 'block':
			disp = 'none';
			vis =  'hidden';
            txt = '<a href="javascript:animatedcollapse.toggle(\'test1\')">Hide this Deal</a>';
			break;
		default:
			disp = 'none';
			vis =  'hidden';
            txt = 'Show';
		}			
	e.display = disp;
	e.visibility = vis;
    t.innerHTML = txt;
 
	}
	
</script>
It doesnt work unless i have <div id="h0" style="visibility:hidden;display:none"></div> there. How do I remove it?
__________________
Websites Created;
warscope.com
ratepayers.org.nz
lothop is offline
Reply With Quote
View Public Profile
 
Old 06-18-2010, 06:48 PM Re: Toggle text change on click
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,384
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
h0 is the ID of the element to hide/show onclick.

Where does the JS class "animatedcollapse" get defined?
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 06-19-2010, 12:39 AM Re: Toggle text change on click
lothop's Avatar
Ultra Talker

Posts: 303
Trades: 0
HTML Code:
<script type="text/javascript" src="animatedcollapse.js"></script>

<script>
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
//-->
</script>
<script type="text/javascript">

animatedcollapse.addDiv('test1', 'fade=1,speed=300,height=360px')
animatedcollapse.init()


</script>
animatedcollapse.js is quite a bit longer.
All I really need is for it to change the link " Hide " to " Show " when clicked. It is working fine, but would be nice to be able to remove the <div id="h0" as it isnt needed
__________________
Websites Created;
warscope.com
ratepayers.org.nz

Last edited by lothop; 06-19-2010 at 12:42 AM..
lothop is offline
Reply With Quote
View Public Profile
 
Old 06-19-2010, 01:35 PM Re: Toggle text change on click
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,384
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Then simply remove it and any references to it in the script.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to Toggle text change on click
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.36733 seconds with 12 queries