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
using a var in a code
Old 12-04-2006, 12:52 PM using a var in a code
Skilled Talker

Posts: 60
Name: tami
Trades: 0
is there a way to use a variable instead of thums1?
Code:
document.all.thumbs1.style.visibility = 'visible';
i have a few divs with id's thumbs1, thumbs2, thumbs3...
and i have a next and a back button that goes through the diffrent dives,

Code:
function nextBtn(){
 
 document.all.thumbs2.style.visibility = 'visible'; 
  document.all.thumbs1.style.visibility = 'hidden'; 
  }
function prevBtn(){
 document.all.thumbs1.style.visibility = 'visible'; 
  document.all.thumbs2.style.visibility = 'hidden'; 
   }
now it works only if i have two dives. so i want to add a var and use it something like this each time the buttons are pressed stat+=stat();
pizza is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-06-2006, 02:39 AM Re: using a var in a code
Novice Talker

Posts: 9
Location: Russian Federation
Trades: 0
First, forget about document.all collection! Use document.getElementById() instead of it.
Secondly, show on an example of (x)html-code which will help to understand what is necessary to do.
I believe, that all is very simple, but I not absolutely have understood you.

Last edited by _ru_; 12-06-2006 at 02:41 AM..
_ru_ is offline
Reply With Quote
View Public Profile
 
Old 12-10-2006, 07:51 AM Re: using a var in a code
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
One way is to recode as;
Code:
function nextBtn(ele1,ele2){
 
 document.all.ele2.style.visibility = 'visible'; 
  document.all.ele1.style.visibility = 'hidden'; 
  }
function prevBtn(ele1,ele2){
 document.all.ele1.style.visibility = 'visible'; 
  document.all.ele2.style.visibility = 'hidden'; 
   }
the function call would be
Code:
prevBtn('thumbs1','thumbs2')

There are however much simpler ways than having to hard code each element name/id into the function calls.
One would be to have one function that hides all the elements not required then call this before a function showing the one needed.
This is the method I use for http://www.candsdesign.co.uk/article...nus/drop-down/ (JS code available by clicking the Show Code link )
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to using a var in a code
 

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