Reply
using a var in a code
Old 12-04-2006, 12:52 PM using a var in a code
Skilled Talker

Posts: 59
Name: tami
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
 
When You Register, These Ads Go Away!
Old 12-06-2006, 02:39 AM Re: using a var in a code
Novice Talker

Posts: 9
Location: Russian Federation
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
Super Moderator

Posts: 15,313
Location: Blackpool. UK
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!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System | Bits & Bobs
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to using a var in a code
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Webmaster Resources Marketplace:
Software Development Company | Webhosting.UK.com | Text Link Brokers 


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

 


Page generated in 0.11781 seconds with 12 queries