Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Hmm. Anyone go chapter and verse on this one?

Reply
Thread Tools

Hmm. Anyone go chapter and verse on this one?

 
 
The Natural Philosopher
Guest
Posts: n/a
 
      10-17-2007

Consider:

<script type="text/javascript" language="JavaScript">
function foo()
{
var dung;
dung=document.getElementsByName('foo')[0].value;
Alert(dung);
}
</script>
<INPUT type="hidden" name="foo" value="shite">


<b onclick="foo()">Click here for an opinion on Javascript</b>

Works in everything except IE. IE6/7 seems to regard
document.getElementsByName('foo') as including the function itself and
gives an 'error in page' response. Or perhaps it finds it first, and
that's why the error occurs.

I am sure there s some reason why it works in other browsers but not in
IE, but what is it?
 
Reply With Quote
 
 
 
 
The Natural Philosopher
Guest
Posts: n/a
 
      10-18-2007
Randy Webb wrote:
> The Natural Philosopher said the following on 10/17/2007 3:02 PM:
>>
>> Consider:
>>
>> <script type="text/javascript" language="JavaScript">
>> function foo()
>> {
>> var dung;
>> dung=document.getElementsByName('foo')[0].value;
>> Alert(dung);
>> }
>> </script>
>> <INPUT type="hidden" name="foo" value="shite">
>>
>>
>> <b onclick="foo()">Click here for an opinion on Javascript</b>
>>
>> Works in everything except IE.

>
> Firefox2.0: Alert is not defined.
> Opera9: Statement on line 6: Reference to undefined variable: Alert
>
> So, I don't believe your "Works in everything except IE".
>
>> IE6/7 seems to regard document.getElementsByName('foo') as including
>> the function itself and gives an 'error in page' response. Or perhaps
>> it finds it first, and that's why the error occurs.

>
> No, it gives the error message (IE7) of "Object expected" because it is
> trying to call a function named Alert with a parameter of dung and since
> Alert doesn't exist it throws the error.
>
> Try the Error Console in Firefox or Opera and reading the error messages
> there.
>
>> I am sure there s some reason why it works in other browsers but not
>> in IE, but what is it?

>
> I don't believe it works in other browsers because testing shows me that
> it doesn't work in other browsers. Change it to alert instead of Alert
> and try again.


That was the one bit I didn't test.

you have focussed on an obvious bug and completely failed to address the
actual question.

Does that make you look smart? or stoopid?

 
Reply With Quote
 
 
 
 
The Natural Philosopher
Guest
Posts: n/a
 
      10-18-2007
Randy Webb wrote:
> The Natural Philosopher said the following on 10/17/2007 8:33 PM:
>
> <snip>
>
>> That was the one bit I didn't test.
>>
>> you have focussed on an obvious bug and completely failed to address
>> the actual question.

>
> The "bug" being your total inability to write a script?
>


I wrote it and it worked, or didnt work in IE.

What I posted was a demonstrative snippet that I got wrong and didn't test.


The point being that if you have a function and a variable with the same
name, and do a getElementsbyName on the form, in firefox and opera the
input is the zero'th element of the returned array, in IE the browser
throws an error if you access the zeroth element.


>> Does that make you look smart? or stoopid?

>
> Go troll somewhere else please.
>


Stoopid it is.
I guess you simply didn't know the answer.

 
Reply With Quote
 
The Natural Philosopher
Guest
Posts: n/a
 
      10-18-2007
Randy Webb wrote:
> The Natural Philosopher said the following on 10/18/2007 5:40 AM:
>> Randy Webb wrote:
>>> The Natural Philosopher said the following on 10/17/2007 8:33 PM:
>>>
>>> <snip>
>>>
>>>> That was the one bit I didn't test.
>>>>
>>>> you have focussed on an obvious bug and completely failed to address
>>>> the actual question.
>>>
>>> The "bug" being your total inability to write a script?
>>>

>>
>> I wrote it and it worked, or didnt work in IE.
>>
>> What I posted was a demonstrative snippet that I got wrong and didn't
>> test.
>> The point being that if you have a function and a variable with the
>> same name, and do a getElementsbyName on the form, in firefox and
>> opera the input is the zero'th element of the returned array, in IE
>> the browser throws an error if you access the zeroth element.

>
> And I can't duplicate that. This code:
>
> <script type="text/javascript">
> function foo()
> {
> var dung;
> dung=document.getElementsByName('foo')[0].value;
> alert(dung);
> }
>
> </script>
>
> <input type="hidden" name="foo" value="shite">
> <button onclick="foo()">Test</button>
>
> When I click that button in IE7, I get - "shite". No error, no problems,
> it gives me what I expected. The only things I changed from your
> original code was changing Alert to alert. So, what version of IE are
> you getting that error in? And, what is the error message?
>


Ie6 and 7. 'error on page'. In the status bar at the bottom.


When I changed the variable names to make the functions NOT have the
same name as the variables, it worked.
 
Reply With Quote
 
GArlington
Guest
Posts: n/a
 
      10-18-2007
On 18 Oct, 11:10, The Natural Philosopher <(E-Mail Removed)> wrote:
> Randy Webb wrote:
> > The Natural Philosopher said the following on 10/18/2007 5:40 AM:
> >> Randy Webb wrote:
> >>> The Natural Philosopher said the following on 10/17/2007 8:33 PM:

>
> >>> <snip>

>
> >>>> That was the one bit I didn't test.

>
> >>>> you have focussed on an obvious bug and completely failed to address
> >>>> the actual question.

>
> >>> The "bug" being your total inability to write a script?

>
> >> I wrote it and it worked, or didnt work in IE.

>
> >> What I posted was a demonstrative snippet that I got wrong and didn't
> >> test.
> >> The point being that if you have a function and a variable with the
> >> same name, and do a getElementsbyName on the form, in firefox and
> >> opera the input is the zero'th element of the returned array, in IE
> >> the browser throws an error if you access the zeroth element.

>
> > And I can't duplicate that. This code:

>
> > <script type="text/javascript">
> > function foo()
> > {
> > var dung;
> > dung=document.getElementsByName('foo')[0].value;
> > alert(dung);
> > }

>
> > </script>

>
> > <input type="hidden" name="foo" value="shite">
> > <button onclick="foo()">Test</button>

>
> > When I click that button in IE7, I get - "shite". No error, no problems,
> > it gives me what I expected. The only things I changed from your
> > original code was changing Alert to alert. So, what version of IE are
> > you getting that error in? And, what is the error message?

>
> Ie6 and 7. 'error on page'. In the status bar at the bottom.
>
> When I changed the variable names to make the functions NOT have the
> same name as the variables, it worked.


I can see that you are talking about the same thing not understanding
each other...
OP puts his/her Javasript INSIDE the body (NOT in head) before the
input field. So when he/she runs the script
document.getElementsByName('foo')[0] refers to the FUNCTION foo and
generates the error trying to access attribute value which function
WILL NOT have...
Everybody else assumes that Javascript is included in head of the page
and so do NOT experience any errors.

 
Reply With Quote
 
beegee
Guest
Posts: n/a
 
      10-18-2007
On Oct 17, 3:02 pm, The Natural Philosopher <(E-Mail Removed)> wrote:

> I am sure there s some reason why it works in other browsers but not in
> IE, but what is it?


There is a bug in the implementation of getElementsByName in IE 6 and
7. The symptoms differ but your's are most like related. Read about
it and a fix, here:

http://forums.microsoft.com/MSDN/Sho...eID=1&pageid=0

And please stop whining about javascript. Go to Yahoo User Interface
pages and watch Crockford's video on Advanced Javascript. Right now
you are looking at about 10% of the language and calling it crap. It
makes you look ignorant and trollish.

Bob

 
Reply With Quote
 
Henry
Guest
Posts: n/a
 
      10-18-2007
On Oct 18, 4:03 pm, Randy Webb wrote:
> GArlington said the following on 10/18/2007 9:51 AM:

<snip>
>> So when he/she runs the script document.getElementsByName('foo')[0]
>> refers to the FUNCTION foo and generates the error trying to access
>> attribute value which function WILL NOT have...

>
> No, it doesn't. The function is not executed until you click on the
> bold text in the original, the button in the latter. And, before
> it is dreamed about, changing it back to a bold element didn't
> make any difference either.


The code will not error on IE until someone puts the form elements
into a FORM element. At that point IE augments the scope chain of the
function that it creates from the intrinsic event attribute, and it
places the FORM element on that augmented scope chain. Thus when the
Identifier - foo - is resolved against this augmented scope chain an
object on the chain above the global object is found to have a 'foo'
property and the resulting value of - foo - is the value of that
property of the FORM element and not the global function.

>> Everybody else assumes that Javascript is included in head of the
>> page and so do NOT experience any errors.

>
> Voodoo programming. Putting my script block before the closing body
> tag had no impact on errors. I still don't get one.


It certainly is an odd proposition that moving the code into the HEAD
would make any difference.

 
Reply With Quote
 
The Natural Philosopher
Guest
Posts: n/a
 
      10-18-2007
GArlington wrote:
> On 18 Oct, 11:10, The Natural Philosopher <(E-Mail Removed)> wrote:
>> Randy Webb wrote:
>>> The Natural Philosopher said the following on 10/18/2007 5:40 AM:
>>>> Randy Webb wrote:
>>>>> The Natural Philosopher said the following on 10/17/2007 8:33 PM:
>>>>> <snip>
>>>>>> That was the one bit I didn't test.
>>>>>> you have focussed on an obvious bug and completely failed to address
>>>>>> the actual question.
>>>>> The "bug" being your total inability to write a script?
>>>> I wrote it and it worked, or didnt work in IE.
>>>> What I posted was a demonstrative snippet that I got wrong and didn't
>>>> test.
>>>> The point being that if you have a function and a variable with the
>>>> same name, and do a getElementsbyName on the form, in firefox and
>>>> opera the input is the zero'th element of the returned array, in IE
>>>> the browser throws an error if you access the zeroth element.
>>> And I can't duplicate that. This code:
>>> <script type="text/javascript">
>>> function foo()
>>> {
>>> var dung;
>>> dung=document.getElementsByName('foo')[0].value;
>>> alert(dung);
>>> }
>>> </script>
>>> <input type="hidden" name="foo" value="shite">
>>> <button onclick="foo()">Test</button>
>>> When I click that button in IE7, I get - "shite". No error, no problems,
>>> it gives me what I expected. The only things I changed from your
>>> original code was changing Alert to alert. So, what version of IE are
>>> you getting that error in? And, what is the error message?

>> Ie6 and 7. 'error on page'. In the status bar at the bottom.
>>
>> When I changed the variable names to make the functions NOT have the
>> same name as the variables, it worked.

>
> I can see that you are talking about the same thing not understanding
> each other...
> OP puts his/her Javasript INSIDE the body (NOT in head) before the
> input field. So when he/she runs the script
> document.getElementsByName('foo')[0] refers to the FUNCTION foo and
> generates the error trying to access attribute value which function
> WILL NOT have...
> Everybody else assumes that Javascript is included in head of the page
> and so do NOT experience any errors.
>

Ah. You HAVE explained it. Except why it works in firefox, but not in IE6.
 
Reply With Quote
 
The Natural Philosopher
Guest
Posts: n/a
 
      10-18-2007
Henry wrote:
> On Oct 18, 4:03 pm, Randy Webb wrote:
>> GArlington said the following on 10/18/2007 9:51 AM:

> <snip>
>>> So when he/she runs the script document.getElementsByName('foo')[0]
>>> refers to the FUNCTION foo and generates the error trying to access
>>> attribute value which function WILL NOT have...

>> No, it doesn't. The function is not executed until you click on the
>> bold text in the original, the button in the latter. And, before
>> it is dreamed about, changing it back to a bold element didn't
>> make any difference either.

>
> The code will not error on IE until someone puts the form elements
> into a FORM element. At that point IE augments the scope chain of the
> function that it creates from the intrinsic event attribute, and it
> places the FORM element on that augmented scope chain. Thus when the
> Identifier - foo - is resolved against this augmented scope chain an
> object on the chain above the global object is found to have a 'foo'
> property and the resulting value of - foo - is the value of that
> property of the FORM element and not the global function.
>


After reading that 3 times, it almost makes sense.


>>> Everybody else assumes that Javascript is included in head of the
>>> page and so do NOT experience any errors.

>> Voodoo programming. Putting my script block before the closing body
>> tag had no impact on errors. I still don't get one.

>
> It certainly is an odd proposition that moving the code into the HEAD
> would make any difference.
>

I wouldnt know. My interest is avoiding pitfalls. Not becoming an expert
in a language I really think is rather badly written.

When I started, there was code that was easy to read and code that was
hard to understand.

Then suddenly everyone started waffling about 'structured programming'.
After a while I realized this was an academic term for what we had all
been doing anyway. Making code easy to read.

The the latest *******s was 'object oriented'. But of course with
backwards compatiblity to procedural. Oh and lets throw typing away cots
its too hard for numpties.

Result is a ****ing plate of spaghetti where to change three bytes in a
browser takes in interpreted variable name with more dots than a
golfball covered in brackets and completely impenetrable, since its
scope is implementation dependent, and, worse depends on where it sits
in some HTML as well.

I am coming to realise that Javascript is possibly the worst language I
have ever had to program in.


 
Reply With Quote
 
The Natural Philosopher
Guest
Posts: n/a
 
      10-18-2007
beegee wrote:
> On Oct 17, 3:02 pm, The Natural Philosopher <(E-Mail Removed)> wrote:
>
>> I am sure there s some reason why it works in other browsers but not in
>> IE, but what is it?

>
> There is a bug in the implementation of getElementsByName in IE 6 and
> 7. The symptoms differ but your's are most like related. Read about
> it and a fix, here:
>
> http://forums.microsoft.com/MSDN/Sho...eID=1&pageid=0
>
> And please stop whining about javascript. Go to Yahoo User Interface
> pages and watch Crockford's video on Advanced Javascript. Right now
> you are looking at about 10% of the language and calling it crap. It
> makes you look ignorant and trollish.
>


I'll whinge if I want to

I AM ignorant of javascript. But not of programming in general. All I
can say is that is is the worst language I've ever used from a personal
point of view.

And Microsnot has made a pigs ear of implementing it.

> Bob
>

 
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
For those who like quoting chapter and verse... Kenny McCormack C Programming 8 03-09-2013 11:15 AM
Free chapter about Python and databases (MySQL and SQLite) Sebastian Bassi Python 5 05-29-2010 07:12 PM
Pcs on network. One sees other but not vice verse Jack D Wireless Networking 1 02-13-2009 12:45 AM
#include verse class class_name Steven T. Hatton C++ 14 04-10-2004 05:18 AM



Advertisments