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.selectedIndex;
var args = createOpts.arguments.length;
for(var i=1;args>i;i++){
s[i-1] = document.getElementById(createOpts.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. 4 1368
On 29/05/2005 18:26, JS wrote:
[snip] s[i-1] = document.getElementById(createOpts.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.arguments
to
arguments
Mike
--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
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.selectedIndex; var args = createOpts.arguments.length; for(var i=1;args>i;i++){ s[i-1] = document.getElementById(createOpts.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.
> > 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="initSels()"> // a method that just calls createOpts with
"sel1" as argument.
<form name="sels" method="post" action="?page=jubii">
Two Dependant SELECT forms:
<select name="sel1" id="sel1" onchange="createOpts(this,'sel1','sel2');">
</select>
<select name="sel2" id="sel2">
<option value="" selected-er- Choose --</option>
</select>
<input name="search" type="text" id="search">
<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.getElementById(createOpts.arguments[i]);
if(s[i-1]==sel)num=i;
}
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 initizialization from any function.
Danny
On Sun, 29 May 2005 16:06:13 -0700, JS <dsa.@asdf.com> 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="initSels()"> // a method that just calls createOpts with "sel1" as argument. <form name="sels" method="post" action="?page=jubii"> Two Dependant SELECT forms: <select name="sel1" id="sel1" onchange="createOpts(this,'sel1','sel2');"> </select> <select name="sel2" id="sel2"> <option value="" selected -er- Choose --</option> </select> <input name="search" type="text" id="search"> <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.getElementById(createOpts.arguments[i]); if(s[i-1]==sel)num=i; }
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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):
|
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...
|
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...
|
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()
{...
|
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...
|
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.
===...
|
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...
|
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:...
|
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...
|
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
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |