473,386 Members | 1,754 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Qn from Novice

(i'm new to javascript) I found the following Javascript and is confused by
its syntax. Why the expression "window.status=input.form[0].value;" is
valid (i verified this in ie6) and has the same result as the expression
"window.status=input.form.elements[0].value"?

As fas as I understand, "input.form" represents the form object. And, this
form object isnt an array. Why we can use array accessing syntax on an
ordinary object?

Any expert can help? thx
================================================== ==========================
=====

<html><HEAD>
<!-- ************************************************** ************** -->
<SCRIPT LANGUAGE="JavaScript">

function displayFormValue(input) {
window.status=input.form[0].value;
// why this syntax can be used instead of "input.form.elements[0].value"
return true;
}
</script>
<!-- ************************************************** ************** -->
</HEAD><body>
<form name=form1>
<input name=text1 type=text onKeyUp="return displayFormValue(this);"
size=10/>

</form>
<br>good to see you
</body>
</html>

Jul 23 '05 #1
2 1148
VK
There is not such array as form(), but there is forms() array:
document.forms[i].elements[j]

displayFormValue(this) gives you a reference on the input element itself, so
in your function you just say:
window.status=input.value;
which is the right syntacs

Any of other syntacs work in IE only because this browser has been built
with a very high tolerance to bad syntacs.
As long as IE can get any rough idea what in the name are trying to do, it
will re-adjust your code internally in some more descent way, and it will
execute the result.
Sometimes it's good, sometimes it's bad (first of all, no guarantee that IE
will decrypt your intentions properly; secondly, it may produce well-hidden
sporadic bugs).
Jul 23 '05 #2


peter wrote:
(i'm new to javascript) I found the following Javascript and is confused by
its syntax. Why the expression "window.status=input.form[0].value;" is
valid (i verified this in ie6) and has the same result as the expression
"window.status=input.form.elements[0].value"?

As fas as I understand, "input.form" represents the form object. And, this
form object isnt an array. Why we can use array accessing syntax on an
ordinary object?


Well what you think is "array accessing syntax" is simply a way to
access properties of an object in JavaScript, see
http://www.jibbering.com/faq/faq_not..._brackets.html

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #3

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

Similar topics

7
by: Christopher Richards | last post by:
It is possible to be able to receive email alerts (say, from Google News) and publish them to a web page automatically? I am a novice as far as PHP goes, but I can open and write to a file and...
2
by: Ewa | last post by:
Hello I have inherited a www service after someone, I have problems with PHP parts. As I am complete novice. I will be very greatful for your help - I did not managed to find an answer myself....
0
by: gilgantic | last post by:
I am a novice a Security Models using Java. Could you recommend some web sites, books, or articles relating to build security models in a Java application. Any suggestion small or large is...
5
by: Marian | last post by:
Hi, I am totaly novice in .NET and I am studying a book about this. There was mentioned "assembly". I did not understand, how function does it has . I would like to know the exact run of code...
2
by: George | last post by:
Is this group for a novice C++ programmers?
4
by: Tim Bird | last post by:
Hi all. I have recently installed VB2005 so teach myself programming, could anyone suggest any links to useful websites, or help sites, Ideally I am looking for tutorials, written for the...
1
by: gretchen.ogrady | last post by:
I admit - I'm a simple user but looking to improve skills. Instructions aren't helping and have searched this group but am getting bogged down by some of the programming-speak. I have a query...
4
by: trond | last post by:
Hello all, Before I start I'd like to point out that I am a complete novice when it comes to asp.net - My background is in network and operating systems, and although I have been doing a bit of...
9
by: Kelii | last post by:
I've been trying to get this piece to work for a few hours, but have given up. I hope someone out there can help, I think the issue is relatively straightforward, but being a novice, I'm stumped....
5
by: =?ISO-8859-2?Q?Istv=E1n?= | last post by:
Could somebody suggest me a novice Python list, please? Thanks, Istvan
0
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
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,...

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.