473,793 Members | 2,948 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Variable Substitution

In the following function:

function showMenu(theMen u, theAction) {
if (document.getEl ementById)
{document.getEl ementById(theMe nu).style.visib ility = theAction;}
else {if (document.layer s) {document.theMe nu.visibility = theAction;}
else {document.all.t heMenu.style.vi sibility = theAction;}}
}

Will the passed value of theMenu be substituted in the last 2 lines or
will it use "theMenu" as the value?

The following words are in the last line:
document
all
theMenu
style
visibility

Since all are reserved words except for "theMenu" is that term
changable?

Do I have to use the following:
eval("document. all."+theMenu+" .style.visibili ty")

I have no way to test it.

--
Dennis Marks
http://www.dcs-chico.com/~denmarks/
To reply change none to dcsi.
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 23 '05 #1
8 5342
Ivo
"Dennis Marks" asked
In the following function:

function showMenu(theMen u, theAction) {
if (document.getEl ementById)
{document.getEl ementById(theMe nu).style.visib ility = theAction;}
else {if (document.layer s) {document.theMe nu.visibility = theAction;}
else {document.all.t heMenu.style.vi sibility = theAction;}}
}

Will the passed value of theMenu be substituted in the last 2 lines or
will it use "theMenu" as the value?
The latter.
Do I have to use the following:
eval("document. all."+theMenu+" .style.visibili ty")


No. Try document.all[theMenu].style.etc.
with square brackets, no eval and no quotes.
HTH
Ivo
Jul 23 '05 #2
Dennis Marks <de******@none. net> writes:
In the following function:

function showMenu(theMen u, theAction) {
if (document.getEl ementById)
{document.getEl ementById(theMe nu).style.visib ility = theAction;}
else {if (document.layer s) {document.theMe nu.visibility = theAction;}
else {document.all.t heMenu.style.vi sibility = theAction;}}
}

Will the passed value of theMenu be substituted in the last 2 lines or
will it use "theMenu" as the value?
It will use the literal text "theMenu", since you are not writing a
variable.

The following words are in the last line:
document
all
theMenu
style
visibility

Since all are reserved words except for "theMenu" is that term
changable?
None of the words are reserved in the Javascript language. The reserved
words are at the end of this page:
<URL:http://www.crockford.c om/javascript/survey.html>
(Hmm, of the six ways a reserved word can't be used, I think the first
should be "As an *unquoted* name in linteral object notation")

The identifiers have the following meaning:

- The variable "document" refers to the variable of that name. This is
usually the global variable, i.e., a property of the global object with
that name. The value of the variable is used.

- The identifier "all" is used as part of a property accessor (due to
the "."), and is not interpreted as a variable. The name of the
identifier is used. The document object of some browsers has a
property called "all", so you find that.

- The identifier "theMenu" is used as part of a property accessor (due
to the "."), and is not interpreted as a variable. The name of the
identifier is used. The object referenced by "document.a ll" may, or
may not, have a property of that name.

etc.
Do I have to use the following:
eval("document. all."+theMenu+" .style.visibili ty")
Never. Never use eval, you don't need it, and the alternatives are
both safer and more efficient.
<URL:http://jibbering.com/faq/#FAQ4_40>

Use:
document.all[theMenu].style.visibili ty
<URL:http://jibbering.com/faq/#FAQ4_39>

In this notation, the part inside the [...] is an *expression*. In
this case it is a expression consisting of a single variable, but
it will be evaluated and its value used, not its name.
I have no way to test it.


No browser at all?

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #3
In article <n0**********@h otpop.com>, Lasse Reichstein Nielsen
<lr*@hotpop.com > wrote:
Dennis Marks <de******@none. net> writes:
In the following function:

function showMenu(theMen u, theAction) {
if (document.getEl ementById)
{document.getEl ementById(theMe nu).style.visib ility = theAction;}
else {if (document.layer s) {document.theMe nu.visibility = theAction;}
else {document.all.t heMenu.style.vi sibility = theAction;}}
}

Will the passed value of theMenu be substituted in the last 2 lines or
will it use "theMenu" as the value?

<snip>
Use:
document.all[theMenu].style.visibili ty
<URL:http://jibbering.com/faq/#FAQ4_39>

In this notation, the part inside the [...] is an *expression*. In
this case it is a expression consisting of a single variable, but
it will be evaluated and its value used, not its name.
I have no way to test it.


No browser at all?


In my browsers only the statement immediately after the "if" is run.
The "else" portions are for other browsers. At least that is my
understanding. Please inform me if I am incorrect. I would like to
simplify it if possible.

The revised function is:

function showMenu(theMen u, theAction) {
if (document.getEl ementById)
{document.getEl ementById(theMe nu).style.visib ility = theAction;}
else {if (document.layer s) {document[theMenu].visibility =
theAction;}
else {document[theMenu].style.visibili ty = theAction;}}
}

--
Dennis Marks
http://www.dcs-chico.com/~denmarks/
To reply change none to dcsi.
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 23 '05 #4
In article <12************ *************@n one.net>,
Dennis Marks <de******@none. net> wrote:
In my browsers only the statement immediately after the "if" is run.
The "else" portions are for other browsers. At least that is my
understanding. Please inform me if I am incorrect. I would like to
simplify it if possible.

The revised function is:

function showMenu(theMen u, theAction) {
if (document.getEl ementById)
{document.getEl ementById(theMe nu).style.visib ility = theAction;}
else {if (document.layer s) {document[theMenu].visibility =
theAction;}
else {document[theMenu].style.visibili ty = theAction;}}
}


You could look in a public library for some books on IE with a cd-rom in
them. Look for IE 4.5.

You could comment out the code for newer browsers and let the new IE run
with the old code.

Robert
Jul 23 '05 #5
Dennis Marks <de******@none. net> writes:
Dennis Marks <de******@none. net> writes:
In my browsers only the statement immediately after the "if" is run.


Then get some more browsers!

Netscape 2 (JavaScript 1.0):
Netscape 3 (JavaScript 1.1):
Netscape 4.00-4.05 (JavaScript 1.2):
Netscape 4.06-4.80 (JavaScript 1.3):
Netscape 7 (JavaScript 1.4):
<URL:http://wp.netscape.com/download/archive.html>
Mozilla FireFox (same engine as Netscape 7, just more recent version):
<URL:http://www.mozilla.org/products/firefox/>

IE 3 (JScript 1.0):
IE 4 (JScript 3.0):
IE 5.01 (JScript 5.0):
IE 5.5 (JScript 5.5):
<URL:http://www.quirksmode. org/browsers/multipleie.html >

Opera v. 3.62, 5.12, 6.06, 7.11 (soon 7.23):
<URL: http://arc.opera.com/pub/opera/win/ >
Opera 7.5:
<URL: http://www.opera.com/download/ >
(I have a version 4 too, if you want it)

Earlier verions of these browsers didn't support Javascript.

If that's not enough, here is the rest:
<URL:http://browsers.evolt. org/>

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #6
Ivo
"Dennis Marks" wrote
In my browsers only the statement immediately after the "if" is run.
The "else" portions are for other browsers. At least that is my
understanding. Please inform me if I am incorrect. I would like to
simplify it if possible.

The revised function is:

function showMenu(theMen u, theAction) {
if (document.getEl ementById)
{document.getEl ementById(theMe nu).style.visib ility = theAction;}
else {if (document.layer s) {document[theMenu].visibility =
theAction;}
else {document[theMenu].style.visibili ty = theAction;}}
}


There are two brackets too many in this function. The one just before "if
(document.layer s)" and the last one should be removed. Currently the logic
looks like:

if (foo) { x=1; } else { if (bar) x=2; } else { x=3; }

which is not logical. I suspect you meant:

if (foo) { x=1; } else if (bar) { x=2; } else{ x=3; }
If you don't have all the browsers you aim to support, there is little in
scripting for them. Even the best need to test. To test stuff for older
browsers, you can usually turn the "if" around (temporarily) with a ! in the
right place.
HTH
Ivo
Jul 23 '05 #7
In article <pt**********@h otpop.com>, Lasse Reichstein Nielsen
<lr*@hotpop.com > wrote:
Dennis Marks <de******@none. net> writes:
Dennis Marks <de******@none. net> writes:
In my browsers only the statement immediately after the "if" is run.


Then get some more browsers!

Netscape 2 (JavaScript 1.0):
Netscape 3 (JavaScript 1.1):
Netscape 4.00-4.05 (JavaScript 1.2):
Netscape 4.06-4.80 (JavaScript 1.3):
Netscape 7 (JavaScript 1.4):
<URL:http://wp.netscape.com/download/archive.html>
Mozilla FireFox (same engine as Netscape 7, just more recent version):
<URL:http://www.mozilla.org/products/firefox/>

IE 3 (JScript 1.0):
IE 4 (JScript 3.0):
IE 5.01 (JScript 5.0):
IE 5.5 (JScript 5.5):
<URL:http://www.quirksmode. org/browsers/multipleie.html >

Opera v. 3.62, 5.12, 6.06, 7.11 (soon 7.23):
<URL: http://arc.opera.com/pub/opera/win/ >
Opera 7.5:
<URL: http://www.opera.com/download/ >
(I have a version 4 too, if you want it)

Earlier verions of these browsers didn't support Javascript.

If that's not enough, here is the rest:
<URL:http://browsers.evolt. org/>

/L


Don't assume I am on a PC. I am on a Mac using system 9. I am not able
to use any of the latest browsers. They require system X and I don't
wish to invest in an upgrade since I might soon switch to a PC. That is
why I asked if the function was correct.

--
Dennis Marks
http://www.dcs-chico.com/~denmarks/
To reply change none to dcsi.
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 23 '05 #8
In article <40************ ***********@new s.wanadoo.nl>, Ivo
<no@thank.you > wrote:
"Dennis Marks" wrote
In my browsers only the statement immediately after the "if" is run.
The "else" portions are for other browsers. At least that is my
understanding. Please inform me if I am incorrect. I would like to
simplify it if possible.

The revised function is:

function showMenu(theMen u, theAction) {
if (document.getEl ementById)
{document.getEl ementById(theMe nu).style.visib ility = theAction;}
else {if (document.layer s) {document[theMenu].visibility =
theAction;}
else {document[theMenu].style.visibili ty = theAction;}}
}


There are two brackets too many in this function. The one just before "if
(document.layer s)" and the last one should be removed. Currently the logic
looks like:

if (foo) { x=1; } else { if (bar) x=2; } else { x=3; }

which is not logical. I suspect you meant:

if (foo) { x=1; } else if (bar) { x=2; } else{ x=3; }
If you don't have all the browsers you aim to support, there is little in
scripting for them. Even the best need to test. To test stuff for older
browsers, you can usually turn the "if" around (temporarily) with a ! in the
right place.
HTH
Ivo

Thank you for your help. I am just creating a general division
show/hide function based on information that I have found in this
group.
I assume that the 3 methods used to show/hide are used by different
browsers. My browsers use getElementById.
The two forms of document{theMen u] do not work on my browsers. My
question is are they valid and are they necessary? I'll remove it if it
is only necessary for a few old browsers.

--
Dennis Marks
http://www.dcs-chico.com/~denmarks/
To reply change none to dcsi.
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 23 '05 #9

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

Similar topics

4
2213
by: bofh | last post by:
I'm working on a project where I need to store a CGI query in a database field. The query contains variables which will be substitued at runtime (e.g., today's date, key to select upon, etc), and may be pointed to different URLs depending upon the table key. The variable substitution works fine when hardcoding into the script, e.g.: $var1='data1';
1
4561
by: Scott | last post by:
I have an XML Document in a format like: <Variable name="Bob">ABCDEFG</Variable> <Variable name="Steve">QWERTYUI</Variable> <Variable name="John">POIUYTR</Variable> <Variable name="Tim">ZXCVBNM</Variable> <Function id="1"> <Parameter type="String">Bob</Parameter> <Parameter type="String">Steve</Parameter>
1
438
by: KERLOG | last post by:
Hello, I found that in "glibc" there is a function to perform variable substitution. It start with $. By digging inside the code of "glibc" I can't find how it's done. Has someone already written such function ? For an old BC3.1 it will be fine.
1
3507
by: Brian Newman | last post by:
I have a form with five rows of text boxes, displaying data. For certain reasons, I can't bind these directly to data records, so I'm using code to load the data into an object, then manually get each field value and assign it to each text box. The text boxes are named like this: txtSPctTrees1 txtSPctShrubs1 txt(etc)1 ... txtSPctTrees2 txtSPctShrubs2 txt(etc)2 ... txtSPctTrees3 ... ....
2
1756
by: JoeT | last post by:
Hi... I want to know if this is possible. I have a database with an attribute which has in it a SQL statement, e.g. select blah from table where key = $x In a PHP function, I read in the above string into $v.
3
5617
by: Skip | last post by:
OK, I'm a novice in JS but have lots of coding experience. I am trying to accomplish something that would seem somewhat simple - BUT IT'S NOT. I have a basic window that calls another window with window.open and passes in 1 value using a querystring i.e., www.myhome.com/mypage?video=BAK-Extension Now when the window opens, I can capture the passed value in a JS function. But if I want to use that in the body of the HTML in a
7
1929
by: damezumari | last post by:
http://www.phpbuilder.net/columns/akent20000610.php3?page=5 variable: function addtime ($datetime, $add, $type) { // How to add time to $datetime (data type datetime) and return it as datetime on the format 'Y-m-d H:i:s' // example calls: // $datetime = addtime ($datetime, 4, 'hours') // add 4 hours
6
1966
by: brad | last post by:
I'd like to do something like this: var = '123' %s = , %var So that, in the end, var is '123' and an empty list is named '123' as well. The list assignments are created during a loop. Thanks, Brad
0
9518
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10211
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
10159
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
10000
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
6776
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
5436
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
5560
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4111
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2917
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.