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
Old 10-03-2007, 04:35 PM Prototype issue
Extreme Talker

Posts: 182
Trades: 0
I am building a sliding faq list. I don't want to use any inline event handlers and i don't want to use numbered IDs (answer1, answer2, etc).

This code almost works. The Event.observe for the DD tags is not setting properly. The error I get returned when I test it out is that the element has no properties.

My js:
Code:
var list_ele;

function init_cToggle ( _0 )

{
	
	list_ele = $ ( _0 );
	
	var dt = list_ele.getElementsByTagName('dt');
	
	var dd = list_ele.getElementsByTagName('dd');
	
	for ( var i=0; i < dt.length; i++ )
	
	{
		
		dd [ i ].style.display = 'none';
		
		Event.observe ( dt [ i ], 'click', function ( ) 
		{
			cToggle( dd[i] );
		
		} );
		
	}
	
}

function cToggle ( _0 )

{
	
	_0.toggle();

}


Event.observe ( window, 'load', function ( )									  
{

	init_cToggle( 'faq_list' );
	   
} );
My HTML (yes i link to prototype.js and my other js libs in the header):
HTML Code:
<dl id="faq_list">

	<dt>Question 1</dt>
	
		<dd>Answer 1...</dd>
	
	<dt>Question 2</dt>
	
		<dd>Answer 2...</dd>
	
	<dt>Question 3</dt>
	
		<dd>Answer 3...</dd>
	
	<dt>Question 4</dt>
	
		<dd>Answer 4...</dd>
	
</dl>
Any takers on this one?
bhgchris is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-04-2007, 02:19 PM Re: Prototype issue
Extreme Talker

Posts: 182
Trades: 0
fixed! it was a scope issue. I found the answer here:

http://lists.evolt.org/pipermail/jav...ly/012274.html

here is my new javascript code:
Code:
/* initialize everything */
function init_cToggle ( _0 )

{
	var list_ele = $ ( _0 );
		
	var dd = list_ele.getElementsByTagName('dd');
	
	var dt = list_ele.getElementsByTagName('dt');
	
	for ( var i=0; i < dd.length; i++ )
	
	{
	
		var x = i;
		
		dd [ x ].style.display = 'none';
		
		dt [ x ].className = 'plus_img';
		
		cObserve ( dt[x], dd[x] );
		
	}
	
}

/* add event listeners */
function cObserve ( _0, _1 )
{
	
	Event.observe ( _0, 'click', function (  ) 
	{
		cToggle( _1, _0 );
	
	} );
	
}

/* do the toggles */
function cToggle ( _0, _1 )

{
	
	//$ ( _0 ).toggle();
	
	if ( $ ( _0 ).getStyle('display') == 'none' )
	
	{
		
		new Effect.BlindDown ( $ ( _0 ), {duration:0.5} );
		
		$ ( _1 ).removeClassName( 'plus_img' );
		
		$ ( _1 ).addClassName( 'minus_img' );
		
	}
	
	else
	
	{
		
		new Effect.BlindUp ( $( _0 ), {duration:0.5} );
		
		$ ( _1 ).removeClassName( 'minus_img' );
		
		$ ( _1 ).addClassName( 'plus_img' );
		
	} 

}

html is the same.

Last edited by bhgchris; 10-04-2007 at 02:20 PM.. Reason: sensitive material
bhgchris is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Prototype issue
 

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.10857 seconds with 12 queries