Getting the LINK innerhtml value from external file
Posted: Sat Jun 13, 2009 4:50 pm
In my html form there are some customer names which are loaded as the html body loads.The names are shown as blank link.I want to get the name of each customer as the link is clicked.Customer names are filled with another php file-customerdb.php.
This is my form-
My customerdb.php file is as below-
I can show the customer names as Httplink and upon clicking getEditForm() javascript function is called.But I want to get the name of each customer for each link upon clicking.I only get first customer name upon clicking.
This is my form-
Code: Select all
<html>
<head>
<script type="text/javascript" >
var xmlhttp = false;
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else if (window.ActiveXObject) {
xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
}
function getCusName()
{
xmlhttp.open("GET","customerdb.php",true);
xmlhttp.onreadystatechange = updateName;
xmlhttp.send(null);
}
function updateName()
{
if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
response=xmlhttp.responseText;
document.getElementById("showCustomer").innerHTML = response;
}
}
function getEditForm()
{
var val=document.getElementById("linkname").innerHTML;
}
</script>
</head>
<body onload="getCusName()">
<div id="showCustomer">Content for id "showCustomer" Goes Here</div>
</body>
</html>Code: Select all
<?php
$dbhost="localhost";
$dbuser="root";
$dbpass="admin";
$dbname="classicmodels";
//Connect to MySQL Server
$con=mysql_connect($dbhost,$dbuser,$dbpass,$dbname);
//Select Database
mysql_select_db($dbname,$con) or die( mysql_error());
//build query
$query = "SELECT customerName FROM customers LIMIT 0,10";
$qry_result = mysql_query($query) or die(mysql_error());
//Build Result String
$display_string = "<table>";
$display_string .= "<tr>";
$display_string .= "<th><b>Customer Names</b></th>";
$display_string .= "</tr>";
// Insert a new row in the table for each person returned
while($row = mysql_fetch_array($qry_result)){
$name=$row[customerName];
$display_string .= "<tr>";
$display_string .= "<td><a id='linkname' href='javascript:getEditForm()'> $name </a></td>";
$display_string .= "</tr>";
}
$display_string .= "</table>";
echo $display_string;
?>