Javascript: Variable scope question

ronnie gauthier ronnieg
Mon May 17 11:37:47 PDT 2004


if this is an actual cut and paste it might help if you close the value
on 1.

On Mon, 16 Sep 2002 22:21:15 -0400
Joel Hammer <Joel at HammersHome.com> wrote:

>I tried your suggestion, and get the same error with netscape 7. opera
>still works fine.
>
>Here is the actual javascript that is causing the problem. It is a bit
>wordy but I don't want to edit it too much for fear of leaving out some
>subtle clue.
>
><form name="form1" action="none">  <----I have defined form1 here!!!!
>
><p><input type=Checkbox name="0"  value = "USE: Lung: All specimens."
>onClick = "ProcessChoice(this.form,name)" > USE: Breast: All
>specimens.</p><p id="intro"><input type=Checkbox name="1"  value =
>"Surgical Pathology Cancer Case Summary onClick =
                                     ^^^^^^^^

>"ProcessChoice(this.form,name)" > <a name = "1" href = "#1"
>title="Center this section">Surgical Pathology Cancer Case Summary
></a></p><p><input type=Checkbox name="2"  value = "LUNG  $1" onClick =
>"ProcessChoice(this.form,name)" > <a name = "2" href = "#2"
>title="Center this section">LUNG  </a></p>
>
>======Lots of stuff snipped out===========
>
>p><input type=Checkbox name="119"  value = "     COMMENT ? $1" onClick
>= "ProcessChoice(this.form,name)" > <a name = "119" href = "#119"
>title="Center this section">100 ___  COMMENT ? </a></p>            
>
></form>     <----Close form here
>
><script>
>document.form1[1].checked = true  <----This gives the error (form1 not
>defined.)
>
>document.form1[2].checked = true         
></script>
>NOTE: The javascript is actually sourced in with an src statement, with
>all the proper incantations, like so:
><script src="Tail.js" language = "javascript" type="text/javascript">
></script> Any suggestion accepted gratefully.
>Joel
>
>
>On Mon, Sep 16, 2002 at 07:45:32PM -1000, jmcd9336 wrote:
>> Are you explicitly accessing the dom i.e using window. or document. ?
>> 
>> Also are you using methods defined in a later javascript version
>while the > browser only paritially supports EMCAScript or javascript
>1.whatever > 
>> netscape has some great js resources
>> 
>> http://developer.netscape.com/docs/manuals/js/core/jsref14/index.htm
>> 
>> <body>
>> <form name="form1" action="none">
>>    Big long form
>>    <input type=checkbox name=checkbox1>
>> </form>
>> <script language="javascript">
>> document.form1.checkbox1.checked = true;
>> </script>
>> </body>
>> </html>
>> 
>> 
>> 
>> On Sun, 8 Sep 2002 05:25, Joel Hammer wrote:
>> > I would appreciate it if anyone could comment on this.
>> >
>> > I have written a long javascript, which, at the end of the day,
>only runs> > on Opera and IE. (netscape, galeon, konqueror, mozilla 
>all fail to run> > correctly.)
>> >
>> > I am trying to track down why netscape 6.2 won't work.
>> > One reason seems to be the typeof command. Netscape doesn't seem to
>support> > it. This is a small annoyance.
>> >
>> > But, a very big problem seems to be variable scope.
>> >
>> > It is looking like IE and opera will allow a function to simply use
>a> > global variable whereas Netscape insists that the variable, at
>least if it> > is an array, be explicitly passed to it. This is
>fixable.> >
>> > The third problem I don't know how to describe in few words. So,
>I'll give> > the example:
>> > <html>
>> > <body>
>> > <form name = "form1" action = "none">
>> >    Big long form
>> > </form>
>> > <script>
>> > form1[1].checked = true
>> > </script>
>> > </body>
>> > </html>
>> > Results in a form1 not defined error.
>> > The odd thing is, netscape's later behavior indicates it knows
>about form1.> >
>> > Opera and IE handle this situation just fine.
>> >
>> > So, I am confused.
>> >
>> > Any insight appreciated.
>> > Joel
>> >
>> >
>> > _______________________________________________
>> > Linux-users mailing list
>> > Linux-users at linux-sxs.org
>> > Unsubscribe/Suspend/Etc ->
>> > http://www.linux-sxs.org/mailman/listinfo/linux-users
>> 
>> 
>> _______________________________________________
>> Linux-users mailing list
>> Linux-users at linux-sxs.org
>> Unsubscribe/Suspend/Etc ->

>http://www.linux-sxs.org/mailman/listinfo/linux-users_________________
>______________________________ Linux-users mailing list
>Linux-users at linux-sxs.org
>Unsubscribe/Suspend/Etc ->
>http://www.linux-sxs.org/mailman/listinfo/linux-users


More information about the Linux-users mailing list