[Javascript] global vars prob

Julien Nadeau junado at junado.com
Wed Sep 28 12:47:54 CDT 2005


What happends is that you set your function to a litteral  
"products_price_return(id);", therefore, when called, the function  
reads the value from "id" rather than say, "products_price_return(5);".

You should look into settings it like this (although this is *evil*),  
this might work:
     inputProductsPrice.setAttribute("onfocus", "products_price_return 
(" + id + ");");

Let me re-state that this is evil ;)

Julien Nadeau
junado at junado.com

Le 05-09-28 à 10:19, Michael Borchers a écrit :

> 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?
>
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20050928/939a0b98/attachment.htm>


More information about the Javascript mailing list