Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-11-2004, 02:41 AM   PM User | #1
questor
New Coder

 
Join Date: May 2004
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
questor is an unknown quantity at this point
how can i access a dynamically named variable?

Well, here's what it does. some php echos out a bunch of javascript variables. then the user makes a select box choice. the select box choice value equals the 'dt number', which is part of the javascript variables outputted by php. so i then need to be able to have javascript access a dynamically named variable.

Thus:

Code:
function selector()
{
var selected = document.selectForm.selectBox.options[document.selectForm.selectBox.selectedIndex].value;

<?
// import employee data into javascript //
$sql2 = "SELECT dt FROM employment";
$sql2 = mysql_query($sql2);
while ($row = mysql_fetch_array($sql2, MYSQL_ASSOC))
 {      
 foreach ($row as $dt) 
  { 
  $sql3 = "SELECT name FROM employment WHERE dt=".$dt;
  $sql3 = mysql_query($sql3);
  $name = mysql_result($sql3,0);
  echo "var dt" . $dt . "_name = '" . $name . "';\n";
  }
 }
?>

var current = 'dt' + selected + '_name';
document.write(current);
}
questor is offline   Reply With Quote
Old 08-11-2004, 02:42 AM   PM User | #2
questor
New Coder

 
Join Date: May 2004
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
questor is an unknown quantity at this point
Right now it just prints:

dtXXXXX_name

That's the NAME of the variable. I want it to OUTPUT the CONTENT of that variable.
questor is offline   Reply With Quote
Old 08-11-2004, 03:03 AM   PM User | #3
glenngv
Supreme Master coder!


 
glenngv's Avatar
 
Join Date: Jun 2002
Location: Los Angeles, CA Original Location: Philippines
Posts: 10,241
Thanks: 0
Thanked 112 Times in 111 Posts
glenngv will become famous soon enough
echo js array instead of normal variables.
Code:
function selector()
{
    var dt = new Array();
    ...
    <?
         ...
        echo "dt[" . $dt . "] = '" . $name . "';\n";
    ?>
    document.write(dt[selected]);
}
__________________
Glenn
_____________________________________________
Play Tower of Hanoi Android app (Ad-FREE!)
Play Tower of Hanoi Android app (FREE!)
Go to Tower of Hanoi Leaderboard
Play Tower of Hanoi Facebook app
glenngv is offline   Reply With Quote
Old 08-11-2004, 03:51 AM   PM User | #4
questor
New Coder

 
Join Date: May 2004
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
questor is an unknown quantity at this point
I'm getting 'dt is undefined', on the first line of dt[xxxxx] = 'somebody's name'...
questor is offline   Reply With Quote
Old 08-11-2004, 03:58 AM   PM User | #5
glenngv
Supreme Master coder!


 
glenngv's Avatar
 
Join Date: Jun 2002
Location: Los Angeles, CA Original Location: Philippines
Posts: 10,241
Thanks: 0
Thanked 112 Times in 111 Posts
glenngv will become famous soon enough
Did you add var dt = new Array(); in the first line of the function?
__________________
Glenn
_____________________________________________
Play Tower of Hanoi Android app (Ad-FREE!)
Play Tower of Hanoi Android app (FREE!)
Go to Tower of Hanoi Leaderboard
Play Tower of Hanoi Facebook app
glenngv is offline   Reply With Quote
Old 08-11-2004, 03:59 AM   PM User | #6
questor
New Coder

 
Join Date: May 2004
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
questor is an unknown quantity at this point
You Are The Bizomb!
questor is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:37 AM.


Advertisement
Log in to turn off these ads.