Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript - using parameters 2

Status
Not open for further replies.

BigMentor

Technical User
May 15, 2009
10
0
0
GB
Hi

I have a series of Javascript functions

Three hundred of them to be precise


function openSub1()
{
document.all.sub1B.style.display = 'block'
}

function openSub2()
{
document.all.sub2B.style.display = 'block'
}

Through to . . .

function openSub300()
{
document.all.sub300B.style.display = 'block'
}


I would like to have a Generalised function that gets the number as
a parameter - like


function openSubGeneral(nNumber)
{
//But how do I get the "Paramer Number" in the next line ????
document.all.sub296B.style.display = 'block'
}


Thanks in anticipation

Pete (Northolt UK)

 
First, document.all is for IE only, so no one viewing your site with any other browser will be able to use that functionality.

You can use something like this:

Code:
function openSub(nNumber)
{
document.getElementById('sub' + nNumber + 'b').style.display = 'block';
}

Lee
 
Thanks Mister Lee

If only my brain had been working, I would not have got into such a loonie position !!

Pete (Northolt UK)
 
Hi

Lee said:
First, document.all is for IE only
That "only" is generally correct, but is not exact.

Because many self-proclaimed webmasters believe that Explorer is the standard, many other browsers had to implement a fake [tt]document.all[/tt].

We discussed about that in thread216-1536016 and thread216-1546473.

( Of course, I agree, the correct solution is the one suggested by Lee. )

Feherke.
 
Thanks for the info, feherke. I didn't realize that the Mozilla browsers had a way out for document.all code.

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top