Frances said the following on 9/19/2005 1:30 PM:
> Lee wrote:
>
>> Frances said:
>>
>>>
>>> <html>
>>> <head>
>>> <script>
>>> function doIt() {
>>> var list = document.forms[0].product;
>>> var selItem = list.options[list.selectedIndex].value;
>>> ^^^^^^^
>>> </head>
>>>
>>>
>>> <body>
>>> <script>
>>> document.writeln('<div id="' + selItem + '">');// var not being
>>> ^^^^^^^^ // read here..
>>> // how do I pass it from function to here?
>>> </script>
>>> </body>
>>>
>>> this is for dynamic content.. what prints depens on what item user
>>> selects in sel obj.. thank you..
>>
>>
>>
>> It's not really a matter of visibility between the head
>> and body. You've declared the variable selItem to be
>> local to function doIt().
>>
>> Removing the "var" keyword from the declaration will make
>> the variable global.
>>
>
> oh gosh, I see, it's like java then.....:)
>
> so this will make it global:
>
> var list;
> var selItem;
> function doIt() {
> list = document.forms[0].product;
> selItem = list.options[list.selectedIndex].value;
> }
>
> thank you all very much for your responses......
>
This makes it global also:
list = '';
selItem = '';
But your problem seems to be that you are trying to access a variable
that is inside a function but you are trying to access it before the
functions is executed. That means the variable has not been defined, nor
created yet, so you get the error.
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Received on Tue Oct 18 03:25:23 2005