Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Qn from Novice

Reply
Thread Tools

Qn from Novice

 
 
peter
Guest
Posts: n/a
 
      12-03-2004
(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>





 
Reply With Quote
 
 
 
 
VK
Guest
Posts: n/a
 
      12-03-2004
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).


 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      12-03-2004


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/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
WLAN novice with connection problem =?Utf-8?B?Sm9yZw==?= Wireless Networking 1 06-07-2005 10:03 PM
Novice needs help! Connection Problem MAG7577 Wireless Networking 1 01-07-2005 12:11 AM
Novice needs help! Connection Problem MAG7577 Wireless Networking 2 01-07-2005 12:10 AM
O.K. novice at work here!! Please advise.. =?Utf-8?B?Umljaw==?= Wireless Networking 8 12-24-2004 02:50 AM
wireless novice need help =?Utf-8?B?d2F5bmVyMTIzMTIz?= Wireless Networking 1 11-04-2004 01:34 PM



Advertisments