473,387 Members | 1,585 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,387 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 1322
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;
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.