473,700 Members | 2,655 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Wierd syntax for if statement

JS
This piece of code is from a JavaScript. The function createOpts takes one
or more SELECT objects as arguments.
function createOpts(sel) {
var s = new Array();
var num = 0;
var n = sel.selectedInd ex;
var args = createOpts.argu ments.length;
for(var i=1;args>i;i++) {
s[i-1] = document.getEle mentById(create Opts.arguments[i]);
if(s[i-1]==sel)num=i;
}
if(args>1){
if(s[num])sel = s[num];
else return;
}
....
....
....
....
}
I don't get the last line in the for-loop. How can one of the arguments that
are stored in array "s" equal "sel"?

In the if statment I can't see how "s[num]" can evaluate to true or false.
Jul 23 '05 #1
4 1381
On 29/05/2005 18:26, JS wrote:

[snip]
s[i-1] = document.getEle mentById(create Opts.arguments[i]);
if(s[i-1]==sel)num=i;
[moved:] I don't get the last line in the for-loop. How can one of the
arguments that are stored in array "s" equal "sel"?
In the preceeding line, an object reference is assigned to an element of
the array, s. The equality test then examines this object reference, and
the reference that is sel. If they both refer to the same object, the
operator will evaluate to true.

var a = {},
b = {};

a != b

a == a && b == b

Object equality is performed in terms of the same object; even if all of
the properties of two objects are the identical, they won't be
considered equal as they two separate objects.

[snip]
if(s[num])sel = s[num];
[snip]
In the if statment I can't see how "s[num]" can evaluate to true or false.


All types in ECMAScript can be converted to a boolean:

string Empty strings ('') are false. All others are true.
number Zero (0) is false. All other numbers are true.
boolean No conversion
null Always false
undefined Always false
object Always true
function Always true

I said this last time you posted part of this code: accessing the
arguments object through a reference to a function is deprecated. In
other words, change occurances of

createOpts.argu ments

to

arguments

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #2
Lee
JS said:

This piece of code is from a JavaScript. The function createOpts takes one
or more SELECT objects as arguments.
function createOpts(sel) {
var s = new Array();
var num = 0;
var n = sel.selectedInd ex;
var args = createOpts.argu ments.length;
for(var i=1;args>i;i++) {
s[i-1] = document.getEle mentById(create Opts.arguments[i]);
if(s[i-1]==sel)num=i;
}
if(args>1){
if(s[num])sel = s[num];
else return;
}
...
...
...
...
}
I don't get the last line in the for-loop. How can one of the arguments that
are stored in array "s" equal "sel"?

In the if statment I can't see how "s[num]" can evaluate to true or false.


A paragraph written in English is not "an English".
Code written in Javascript is not "a Javascript".

The "sel" argument to the function is not a Select object,
it's a reference to a Select object. If one of the elements
of s[] is a reference to that same object, then they will
compare as "equal".

Any value will evaluate to true or false.
In the case of s[num], the value will evaluate as "true" if
there is an element at index "num" with any value other than
false or zero.

Jul 23 '05 #3
JS
> > I don't get the last line in the for-loop. How can one of the
arguments that are stored in array "s" equal "sel"?
In the preceeding line, an object reference is assigned to an element of
the array, s. The equality test then examines this object reference, and
the reference that is sel. If they both refer to the same object, the
operator will evaluate to true.

var a = {},
b = {};

a != b

a == a && b == b

Object equality is performed in terms of the same object; even if all of
the properties of two objects are the identical, they won't be
considered equal as they two separate objects.

The first time I make a call to createOpts I only use one argument (the
first select object "sel1"). The second time I call createOpts I use three
arguments (this, sel1, sel2):

<body onload="initSel s()"> // a method that just calls createOpts with
"sel1" as argument.
<form name="sels" method="post" action="?page=j ubii">
Two Dependant SELECT forms:&nbsp;&nb sp;&nbsp;
<select name="sel1" id="sel1" onchange="creat eOpts(this,'sel 1','sel2');">
</select>&nbsp;&n bsp;&nbsp;&nbsp ;&nbsp;&nbsp;
<select name="sel2" id="sel2">
<option value="" selected-er- Choose --</option>

</select>
&nbsp;
<input name="search" type="text" id="search">
&nbsp;
<input type="submit" name="Submit" value="Search">
</form>

But I cannot understand which argument "sel" refers to in :

for(var i=1;args>i;i++) {
s[i-1] = document.getEle mentById(create Opts.arguments[i]);
if(s[i-1]==sel)num=i;
}
Jul 23 '05 #4

You may want to elaborate your query a bit more, too vague to determine,
js doesn't have a native createOps() method, so, it has to be custom, I
don't see it posted, .arguments[i] is just picking up arguments off the
function call and puttting it in a 'S' array, so, it could be in the
initializer function or elsewhere, but, is more than likely global
variable thus being called without initizializatio n from any function.

Danny
On Sun, 29 May 2005 16:06:13 -0700, JS <dsa.@asdf.co m> wrote:
> I don't get the last line in the for-loop. How can one of the
> arguments that are stored in array "s" equal "sel"?


In the preceeding line, an object reference is assigned to an element of
the array, s. The equality test then examines this object reference, and
the reference that is sel. If they both refer to the same object, the
operator will evaluate to true.

var a = {},
b = {};

a != b

a == a && b == b

Object equality is performed in terms of the same object; even if all of
the properties of two objects are the identical, they won't be
considered equal as they two separate objects.

The first time I make a call to createOpts I only use one argument (the
first select object "sel1"). The second time I call createOpts I use
three
arguments (this, sel1, sel2):

<body onload="initSel s()"> // a method that just calls createOpts with
"sel1" as argument.
<form name="sels" method="post" action="?page=j ubii">
Two Dependant SELECT forms:&nbsp;&nb sp;&nbsp;
<select name="sel1" id="sel1" onchange="creat eOpts(this,'sel 1','sel2');">
</select>&nbsp;&n bsp;&nbsp;&nbsp ;&nbsp;&nbsp;
<select name="sel2" id="sel2">
<option value="" selected
-er- Choose --</option>

</select>
&nbsp;
<input name="search" type="text" id="search">
&nbsp;
<input type="submit" name="Submit" value="Search">
</form>

But I cannot understand which argument "sel" refers to in :

for(var i=1;args>i;i++) {
s[i-1] = document.getEle mentById(create Opts.arguments[i]);
if(s[i-1]==sel)num=i;
}


--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Jul 23 '05 #5

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

Similar topics

41
2859
by: John Marshall | last post by:
How about the following, which I am almost positive has not been suggested: ----- class Klass: def __init__(self, name): self.name = name deco meth0: staticmethod def meth0(x):
7
248469
by: Dave | last post by:
I have 2 tables, one with names, and another with addresses, joined by their CIVICID number (unique to the ADDRESSINFO table) in Oracle. I need to update a field in the NAMEINFO table for a particular surname in a particular town. I can select the records fine with this syntax (testing in Oracle SQL* Plus) SELECT NAMEINFO.LASTNAME, NAMEINFO.FIRSTNAME, NAMEINFO.MIDDLENAME, NAMEINFO.GENDER, ADDRESSINFO.REGION FROM NAMEINFO, ADDRESSINFO...
3
1410
by: Sathyaish | last post by:
A practice excercise from K&R. Kindly read the comments within the program. I'd be very grateful to people who helped. Why is it that I get the wierd face-like characters on the screen instead of the boolean output 0s or 1s? #include <stdio.h> /*This program is made to check that leaving the brackets around the epxression (c=getchar()) in the statement while ((c=getchar()) !=EOF) produces a boolean output in
13
5029
by: wessoo | last post by:
Hi All. What is The Lvalue Required error message. (What does it mean?Is it an abbreviationof something.) I wrote this test program and I am keeping geting this message. void main() { clrscr();
7
6665
by: kosta | last post by:
hello! one of my forms communicates with a database, and is supposed to add a row to a table using an Insert statement... however, I get a 'oledb - syntax error' exception... I have double checked, and the insert works fine (tried to use it from access)... im using visual C# express 2k5... what could be wrong? thanks!
6
2165
by: Heiko Wundram | last post by:
Hi all! The following PEP tries to make the case for a slight unification of for statement and list comprehension syntax. Comments appreciated, including on the sample implementation. === PEP: xxx Title: Unification of for-statement and list-comprehension syntax
3
1546
by: Tom | last post by:
We are experiencing some wierd debugging behavior. What happens is that, during debugging with VS 2003, the debugger seems to 'skip' statements that are associated with database operations. For instance, I can be single-stepping through a VB.NET program, and once I hit a DB related statement (such as setting command parameters, executing a data reader, etc) the debugger will simply 'skip' ahead a number of statements (if not all the way to...
1
1493
by: samneil | last post by:
I have 1 Database( MS Access) with 9 tables and 6 queries, Now I'm trying to view my 2 different tables on my VB6.0 using 2 Datagrids and 2"adodc".... here are the names of my two tables: "Employee" and "Work" so I've tried opening them, I had no problems with the Employee table, but with my Work table, it says "syntax error on FROM Clause" isn't it WIERD? and I'v asked my classmate to try it on his Computer at home, he had no problems...
2
1535
by: Bobby Edward | last post by:
My site is utilizing asp.net membership. It works perfect on the development machine. I copied the entire directory to the production server. Now it seems that the membership stuff is acting wierd. I can login ok. But it doesn't run the login redirect properly. Also, I wrote a simple test page that consists of this... Protected Sub Page_Load(ByVal sender As Object, ByVal e As
14
5817
by: paresh | last post by:
Is this the valid C statement. int a,b,c; c = 5; <<< a = b = c; Can anyone throw the light on this. -Paresh
0
8648
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
9217
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
9078
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
8974
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
8928
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...
1
6563
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4660
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3094
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
2
2393
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.