473,499 Members | 1,593 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Question about Javascript Variables

Hi...

I was just reviewing some javascript pop up window functions on my
website and I descovered something... that I set the exact same
variable name twice for both functions... which is bookWindow. I
tested this for pages that use both functions and both types of pop
windows work no problem. Is there a problem in that I use the same
variable name twice? Is this considered bad form? Or maybe it makes
not difference at all because the variable only gets used when it is
called upon and then it leave memory.

All help and insite is appreciated.
<script language="JavaScript" type="text/javascript">
<!--
function newWindow(webpage) {
bookWindow = window.open(webpage, "newWin",
"menubar,status,scrollbars,resizable,toolbar,locat ion,height=400,width=500,top=26,left=280")
bookWindow.focus()
}
function msiWindow(webpage) {
bookWindow = window.open(webpage, "msiWin",
"menubar,status,scrollbars,resizable,toolbar,locat ion,height=600,width=754,top=0,left=0")
bookWindow.focus()
}
// -->

Feb 23 '06 #1
2 1149
newspost2000 wrote:
I was just reviewing some javascript pop up window functions on my
website and I descovered something... that I set the exact same
variable name twice for both functions...
[...]
Is there a problem in that I use the same
variable name twice? Is this considered bad form?


There's no problem, but the variable value will be replaced.

You call function A:
X = A
After calling function B:
X = B

If you're not going to use that variable, I suggest you to declare it
using "var", so it won't be acessible out of function.

function getWindow(bla, bla, bla){
var w = window.open(....
:
return w;
}
--
Jonas Raoni Soares Silva
http://www.jsfromhell.com
Feb 23 '06 #2

newspost2000 wrote:
<script language="JavaScript" type="text/javascript">
The language attribute is deprecated, just stick with the type
attribute:

<script type = "text/javascript">
<!--
HTML comment delimiters are unnecessary.
function newWindow(webpage) {
bookWindow = window.open(webpage, "newWin",
"menubar,status,scrollbars,resizable,toolbar,locat ion,height=400,width=500,top=26,left=280")
bookWindow.focus()
}
function msiWindow(webpage) {
bookWindow = window.open(webpage, "msiWin",
"menubar,status,scrollbars,resizable,toolbar,locat ion,height=600,width=754,top=0,left=0")
bookWindow.focus()
}


You could _potentially_ have a problem. Since you have not declared
bookWindow with a "var", the variable is not local to the function.
You are using bookWindow as a global variable, thus you might overwrite
a value that you have assigned earlier. It is generally good form to
declare variables using the var keyword.

Feb 23 '06 #3

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

Similar topics

22
3096
by: Tom Moroow | last post by:
Hi, I'm pretty new to javascript and was wondering how you would piece together a variable name and then assign it a value. I want to create a hidden field and assign it a value based on the value...
9
2151
by: beguigne | last post by:
Below is a snippet of a crude date picking routine for a form. I am a novice at this so, I am hitting my head at why when I select the day, the onChange event gives me a blank. What am I missing?...
1
1593
by: Jay | last post by:
I need to validate 21 sets of radio buttons before submission to the server for calculation and storage. Is it best to validate on the client side using javascript or to validate on the server...
2
1174
by: Ed Jay | last post by:
I have two functions, one of which is called from within the other, which is called from an HTML page. The called function is passed parameters that I'd like to pass to the argument calling the...
2
1415
by: MPA | last post by:
Hi, I am a newbee. All our applications so far were traditional client-server database applications. We are considering now writing our main application with Visual Studio .NET. Basically we...
5
5638
by: Joh | last post by:
I'm using mailto to open up an email that have a hyperlink in the body. The hyperlink passes two variables Name and Emailadress. The problem is that only the first variable Name show up in the...
9
1640
by: Paul Gorodyansky | last post by:
Hi, User call my Virtual Keyboard by pressing a button. But many user may never need it, so I don't want to load 100k of JavaScript code _when page is being loaded_ - I want to load my...
1
25617
pbmods
by: pbmods | last post by:
VARIABLE SCOPE IN JAVASCRIPT LEVEL: BEGINNER/INTERMEDIATE (INTERMEDIATE STUFF IN ) PREREQS: VARIABLES First off, what the heck is 'scope' (the kind that doesn't help kill the germs that cause...
6
1198
by: 182719 | last post by:
Hi, can someone please explain variables and what I am doing wrong here? <script> x=1; alert(x); </script>
4
1300
dmjpro
by: dmjpro | last post by:
Today i looked at JavaScript closures. There i came across a thing closure comes in when an inner function defined inside an outer function. So when outer function exits and returns the inner...
0
7009
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
7178
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,...
1
6899
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...
0
7390
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...
0
5475
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,...
1
4919
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3094
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
302
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...

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.