473,288 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,288 software developers and data experts.

Need help fixing a JavaScript

Hi

I'm new to the group so if I make a major blunder posting this here I
apologise in advance.

I'm not a Programmer by any stretch of the imagination and I've been
trying to sort out a small JavaScript that I found here:
http://www.interspire.com/content/ar...and-JavaScript

if I use what is supplied it works fine, but a little further down
there is a enhancement that I just can't get to work. It seems to be
because of the { and }.

This is the script that needs to be fixed:
menu_status = new Array();

function showHide(theidPrefix, theidNum)
{

// show / hide clicked menu element
if (document.getElementById)
{
var switch_id = document.getElementById(theidPrefixtheidNum);

if(menu_statustheidPrefixtheidNum != 'show')
{
switch_id.className = 'show';
menu_statustheidPrefixtheidNum = 'show';
}
else
{
switch_id.className = 'hide';
menu_statustheidPrefixtheidNum = 'hide';
// hide non - clicked menu elements
n = 1;
while( document.getElementById(theidPrefixn) )
if(n !== theidNum)
var hide_id = document.getElementById(theidPrefixn);
hide_id.className = 'hide';
menu_statustheidPrefixn = 'hide';

n;
}
}
}

If anybody here could give me a pointer I would greatly appreciate it.

Regards
Brenton

Aug 24 '06 #1
1 1317
Brenton wrote:
Hi

I'm new to the group so if I make a major blunder posting this here I
apologise in advance.

I'm not a Programmer by any stretch of the imagination and I've been
trying to sort out a small JavaScript that I found here:
http://www.interspire.com/content/ar...and-JavaScript

if I use what is supplied it works fine, but a little further down
there is a enhancement that I just can't get to work. It seems to be
because of the { and }.

This is the script that needs to be fixed:
menu_status = new Array();

function showHide(theidPrefix, theidNum)
{

// show / hide clicked menu element
if (document.getElementById)
{
var switch_id = document.getElementById(theidPrefixtheidNum);
You can't just munge together identifiers and hope the JavaScript
interpreter will work it out. Guessing that 'theidPrefix' and
'theidNum' are strings and that you want to concatenate them:

var switch_id = document.getElementById(theidPrefix + theidNum);

if(menu_statustheidPrefixtheidNum != 'show')
Here you treat the array 'menu_status' as if it was a plain object, so
why not declare it as an object:

var menu_status = {};

Then use it as one:

if ('show' != menu_status[theidPrefix + theidNum])

{
switch_id.className = 'show';
You should keep variables local by using the 'var' keyword unless you
really want them to be global:

var switch_id.className = 'show';

menu_statustheidPrefixtheidNum = 'show';
menu_status[theidPrefix + theidNum] = 'show';

}
else
{
switch_id.className = 'hide';
menu_statustheidPrefixtheidNum = 'hide';
menu_status[theidPrefix + theidNum] = 'hide';

// hide non - clicked menu elements
n = 1;
var n = 1;

while( document.getElementById(theidPrefixn) )
while( document.getElementById(theidPrefix + n) )

if(n !== theidNum)
if(n != theidNum)

I think you mean all the following statements to be inside the 'if' block:

{
var hide_id = document.getElementById(theidPrefixn);
var hide_id = document.getElementById(theidPrefix + n);

hide_id.className = 'hide';
menu_statustheidPrefixn = 'hide';
menu_status[theidPrefix + n] = 'hide';

n;
I think you mean to increment n here:

n++;

}
}
}
No guarantees...

I seems rather pointless storing the display property value in an object
since you can get it directly from the element.

Guessing that you want to show only one at a time, just store a
reference to the one that is currently visible. Then when you want to
show another one, hide the one that the variable references, show the
one you want and change the reference to the new one, e.g.:

var menu_status;

function showHide(theidPrefix, theidNum)
{
if (!document.getElementById) return;
var el = document.getElementById(theidPrefix + theidNum);
if ('object' == typeof menu_status && menu_status != el){
menu_status.className = 'hide';
}
el.className = 'show';
menu_status = el;
}

That probably won't suit, but may give you an idea of how to go about it.
--
Rob
Aug 24 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: George Hester | last post by:
In a page I have when the user left-clicks the page a Input box for a form gets the focus. But if the user right-clicks the page the Input box is not getting the focus. I'd like the Input box to...
9
by: Dr John Stockton | last post by:
Assuming default set-ups and considering all reasonable browsers, whatever that may mean, what should an author expect that his readers in general will see (with visual browsers) for a page with...
3
by: MS News | last post by:
Hi all is there a way to fix an id like id=txtCheckedItems aspx changes it to _ctl0_eee_txtCheckedItems in <input name="_ctl0:eee:txtCheckedItems" id="_ctl0_eee_txtCheckedItems"
2
by: TG | last post by:
Hi, I am having a problem tryin to open the connection to a database the nretreiving the informaiton based on the entry of an email address and a password for authentication from the database. ...
18
by: chimalus | last post by:
I am using a table with no column widths specified, letting the table layout manager do its thing for figuring out the column widths, and this works just fine. Now I want to make the table...
12
by: googlegroups | last post by:
Hi, I'm making a javascript program for rolling dice for a roleplaying game that's played in a forum. The die roll gets generated, gets stored as text in a hidden form field, and then gets written...
26
by: Ravindra.B | last post by:
I have declared a global variable which is array of pointers and allocated memory for each array variable by using malloc. Some thing similar to below... static char *arr; main() { int i;
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.