473,563 Members | 2,895 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 1375
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
2829
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
248449
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,...
3
1404
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())...
13
4995
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
6652
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
2155
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
1536
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...
1
1488
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...
2
1531
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...
14
5807
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
7665
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8106
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...
1
7642
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...
0
6255
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...
1
5484
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...
0
5213
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...
0
3643
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...
1
1200
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
924
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...

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.