[Javascript] global vars prob

Mike Dougherty mdougherty at pbp.com
Wed Sep 28 11:00:04 CDT 2005


What value do you expect the variable to hold after you have incremented it to 10?

if you are initializing the variable to "ordersNumRows" (which is zero) then re-incrementing it to 
ten, it will always be 10 at the end of the for() iteration.

you may want to use "var id = ..." inside your procedures so you do not have scoping issues 
between local/procedure variables and global or higher scoped variables

On Wed, 28 Sep 2005 16:19:05 +0200
  "Michael Borchers" <borchers at tridem.de> wrote:
> i am creating new elements within for()
> with a starting var named "id"
> 
> id = ordersNumRows;
> 
> for(o=0;o<ordersNumRowsAdded;o++)
> {
> ...
>  inputProductsPrice.setAttribute("id","products_id[" + id + "][products_price]");
>  inputProductsPrice.onfocus=function() { products_price_return(id); };
> ...
> id++;
> }
> 
> the shown ID in the attribute works fine => 0, 1, 2, ... X (let's say 10)
> 
> but when the function is called, the id always is the highest value at the end of for, f.e. 10
> 
> how do these globals work, do i have to add them with a " + " or similar?
> 
> 
> 
> 
> __________________________________________________________
> This message was scanned by ATX
> 10:18:17 AM ET - 9/28/2005




More information about the Javascript mailing list