RES: [Javascript] dynamic var names

SosCpdGMail soscpd at gmail.com
Tue Aug 7 22:48:20 CDT 2007


Can we use some kind of server side script language or just "plain"
JavaScript? I can't figure how dynamic change anything without any input,
and if the input is in the url already, well, what (maybe where) is the
problem? Today I, to dynamic insert scripts (or images or any html element)
use createElement. With that you can pass a string (your JavaScript code,
including the dynamic variable). 

Close to:

<code>
    var whatever = document.createElement("IMG");
    whatever.id="whatever";
    whatever.src="whatever.gif";
 
void(document.getElementById('anychildlikedivorspam').appendChild(whatever))
;
</code>

This code fit my needs to input a script element (course, that one is about
a img) and run. I use now for responses about bad logins (wrong password or
username). The response come from a php (http_request) document who gives a
redirect or a innerHTML string.


-----Mensagem original-----
De: javascript-bounces at LaTech.edu [mailto:javascript-bounces at LaTech.edu] Em
nome de Terry Riegel
Enviada em: terça-feira, 7 de agosto de 2007 23:21
Para: [JavaScript List]
Assunto: Re: [Javascript] dynamic var names

Ok, I see what you are saying. Here is another one I have used it on.  
For the moment we will put aside security issues...

I have a variable called url ...

url="http://www.example.com?myvar=Joe

It is stored in a string and I slice and dice and get two other  
variables n and v like...

n="myvar"
v="Joe"

And now I want to do the following...

myvar="Joe"

I  can use indirection to do this assignment

@n=v

where @n is the variable myvar


Is there a better way to do this? I realize there are major security  
issues with this example.


Terry




On Aug 7, 2007, at 8:33 PM, Scott Reynen wrote:

> On Aug 7, 2007, at 4:59 PM, Terry Riegel wrote:
>
>> I have always called this indirection, and have found several uses  
>> for it. Not sure about js but I have used it on several server  
>> side projects. Here is a quick outline of one such usage.
>>
>> I had a user editable table that needed quite bit of processing  
>> for each row in the table. I needed a way to cache the results. So  
>> I created (via indirection) a variable whose name was the same as  
>> the ID from each row.
>>
>> So I needed a way to flag that a rows processing had been cached.  
>> I created a variable whose name was the row ID. Since this ID was  
>> assigned in the user editable table I had to use indirection to  
>> read/write to the variable.
>>
>> It is a little confusing, and Javascript may have better ways of  
>> doing this.
>
> I think most scripting languages use hashes, a.k.a. associate  
> arrays, to do something like this, where it's not really necessary  
> that a variable name be defined dynamically, only that some sort of  
> named reference to a value be defined dynamically.  A dynamic array  
> key, e.g. rowIsCached[rowId] = true, works just as well as a  
> dynamic variable name in this case, and removes the risk of naming  
> conflicts with other variables or reserved words.  I think  
> associative arrays and dynamic variable names are both specific  
> forms of indirection, a very general concept of using names/symbols  
> to refer to things indirectly.  Email addresses are another common  
> example of indirection.
>
> Peace,
> Scott
>
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
>

_______________________________________________
Javascript mailing list
Javascript at LaTech.edu
https://lists.LaTech.edu/mailman/listinfo/javascript




More information about the Javascript mailing list