Jump to content

[SOLVED] php and javascript array problem


shadiadiph

Recommended Posts

I have been told this is a php problem and not so much of a javascript problem which is why i am posting it here in php help.

This is almost working when i select an email it shows the name field but it shows more than one name on select as the php echo array returns more than 1 value how can i get it working to show the correct name only? The problem seems to be in defining the php echo "names" in the <script> area!

<?PHP
include("../checkadminlogin.php");
include("../../global/connection.php");

$sql = "select intNameID, email,fname, lname, place from tbladvisorsdetails where place='A' order by intNameID ASC";
$temps01=$DB_site->query($sql);
while ($row=$DB_site->fetch_array($temps01))
{
$selected = ($nameid==$row["intNameID"]) ? ' selected="selected"' : '';
$email_options .= " <option value=\"{$row['intNameID']}\"$selected>{$row['email']}</option>\n";
$js_names_array .= "names[{$row['intNameID']}] = '{$row['fname']} {$row['lname']}';\n";
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>APA</title>
<link rel="stylesheet" type="text/css" href="office.css" />
<script type="text/javascript">
var names = new Array();
<?php echo $js_names_array; ?>

function changeName(value) {
document.getElementById('USEDname').value = (names);
}
</script>

</head>

<body> 

Link to comment
https://forums.phpfreaks.com/topic/136834-solved-php-and-javascript-array-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.