Would something like the following php code be possible in JavaScript? If yes how.
$array = array ( 'firstpage', 'secondpage' );
$$array[0] = 'index.html';
echo ( $firstpage );
| SitePoint Sponsor |
Would something like the following php code be possible in JavaScript? If yes how.
$array = array ( 'firstpage', 'secondpage' );
$$array[0] = 'index.html';
echo ( $firstpage );



I am not aware of anything in JavaScript that would allow you to do this. I think you would have to write some extra code to assign a value to another value.
I could be wrong.
- Pip
---------------------------------------------------------------------------------
Nothing takes the taste out of peanut butter quite like unrequited love.





of course!
var first = ' mouse ';
var cat = first;
alert(cat);
alert(eval(cat));
That'd do you - right?
* doesn't bother testing this - as per usual*
let me know if it doesn't work.
Flawless
---=| If you're going to buy a pet - get a Shetland Giraffe |=---



Good to see someone understands the logic better than most others.![]()
- Pip
---------------------------------------------------------------------------------
Nothing takes the taste out of peanut butter quite like unrequited love.





HUH ?
* doesn't understand which way and to who that insinuation / guesture is meant to swing *
You fancy clarifying that a bit more?
oh - and what you're mad at ?
Flawless
---=| If you're going to buy a pet - get a Shetland Giraffe |=---



That was meant to be a compliment Flawless, and the fire means REDHOT. Maybe I chose the wrong the smiley, but at the time I thought it was appropreate to point out that I think your JS logic is impressive. I can however now see how that could be misunderstood.
Then again, I suppose you don't generally take compliments either.doesn't bother testing this - as per usual![]()
- Pip
---------------------------------------------------------------------------------
Nothing takes the taste out of peanut butter quite like unrequited love.





he he - that's ok - i get what you mean now.
Thanks for the compliment
Flawless
---=| If you're going to buy a pet - get a Shetland Giraffe |=---
All very great, but despite being along the right lines, it doesn't actually demonstrate the real answer to daemon's original question!!!Originally posted by Flawless_koder
of course!
var first = ' mouse ';
var cat = first;
alert(cat);
alert(eval(cat));
That'd do you - right?
* doesn't bother testing this - as per usual*
let me know if it doesn't work.
Flawless
IMHO the answer is more like this:daemon, does that answer your question?!Code:<script language="JavaScript"> //although this is hardcoded, the "myvar" bit is just //a string, and so could be derived from anywhere var newVarName = "testvar"; //ditto var newVarValue = "hello world!"; //turn the variable name and value into a variable with //an assigned value (beware of unescaped quotes when you //do this for real) eval(newVarName + "='" + newVarValue + "'"); //we now have a variable called "testvar", so //let's output the contents! alert(testvar); </script>![]()
MarcusJT
- former ASP web developer / former SPF "ASP Guru"
- *very* old blog with some useful ASP code
- Please think, Google, and search these forums before posting!





.oO( You can tell when blow up dolly gets a puncture! )
j/king mate
Flawless
---=| If you're going to buy a pet - get a Shetland Giraffe |=---
MarcusJT
- former ASP web developer / former SPF "ASP Guru"
- *very* old blog with some useful ASP code
- Please think, Google, and search these forums before posting!
Bookmarks