473,609 Members | 2,187 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(theidP refix, theidNum)
{

// show / hide clicked menu element
if (document.getEl ementById)
{
var switch_id = document.getEle mentById(theidP refixtheidNum);

if(menu_statust heidPrefixtheid Num != 'show')
{
switch_id.class Name = 'show';
menu_statusthei dPrefixtheidNum = 'show';
}
else
{
switch_id.class Name = 'hide';
menu_statusthei dPrefixtheidNum = 'hide';
// hide non - clicked menu elements
n = 1;
while( document.getEle mentById(theidP refixn) )
if(n !== theidNum)
var hide_id = document.getEle mentById(theidP refixn);
hide_id.classNa me = 'hide';
menu_statusthei dPrefixn = 'hide';

n;
}
}
}

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

Regards
Brenton

Aug 24 '06 #1
1 1334
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(theidP refix, theidNum)
{

// show / hide clicked menu element
if (document.getEl ementById)
{
var switch_id = document.getEle mentById(theidP refixtheidNum);
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.getEle mentById(theidP refix + theidNum);

if(menu_statust heidPrefixtheid Num != '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.class Name = 'show';
You should keep variables local by using the 'var' keyword unless you
really want them to be global:

var switch_id.class Name = 'show';

menu_statusthei dPrefixtheidNum = 'show';
menu_status[theidPrefix + theidNum] = 'show';

}
else
{
switch_id.class Name = 'hide';
menu_statusthei dPrefixtheidNum = 'hide';
menu_status[theidPrefix + theidNum] = 'hide';

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

while( document.getEle mentById(theidP refixn) )
while( document.getEle mentById(theidP refix + 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.getEle mentById(theidP refixn);
var hide_id = document.getEle mentById(theidP refix + n);

hide_id.classNa me = 'hide';
menu_statusthei dPrefixn = '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(theidP refix, theidNum)
{
if (!document.getE lementById) return;
var el = document.getEle mentById(theidP refix + theidNum);
if ('object' == typeof menu_status && menu_status != el){
menu_status.cla ssName = '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
2018
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 get the focus no matter where on the page the user clicks be it right-click or left-click. Right now there is no context menu when the user right-clicks. Do you think that's the problem? Any ideas how to get this right-click left-click Input box...
9
3769
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 body like <br><br> Abc <font size=+1> Abc <font size=+1> Abc <font size=+1> Abc <font size=+1> Abc <font size=+1>
3
1590
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
1202
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. Here is my code, can enyone help me out and fix it with the right peices? Private Sub Submit1_ServerClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Submit1.ServerClick Dim db As New BWMDB.Database(Session("Database"))
18
30480
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 dynamic. I have added a filtering mechanism (in javascript) that can be used to hide unneeded rows. However, each time I hide or show rows, the column sizes change, and this doesn't look good. Is there a way that I can preserve the column widths...
12
3112
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 to the mySQL database upon form submission. What I want to do is prevent cheaters from being able to create their own die roll, and the best way I've come up with to do this is to encrypt what gets stored in the hidden form field. However,...
26
2335
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
8534
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8509
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8188
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8374
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6969
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5502
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4002
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4059
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1366
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.