Dear List -
I think we have to revisit this.
The object is to click on an element of a table [name field] and
retrieve the customer number[number field] send th eresult as an Ajax
call to a callback function as a json string, and get back the customer
number as a PHP variable.
Code snippits:
Start:
<div id="e1">
Table:
$results = "<table border=4 cellpadding=5 cellspacing=55 rules=all
frame=box style='table-layout:fixed;'>";
$results .= "<tr><th>Name</th><th>Number</th></tr>";
// generate a table here
for($i=0; $i<10; $i++)
{
$k = $i ;
$results .= "<tr><td id='name$i' >$names[$k] </td><td
id='nums$k'>$nums[$k]</td></tr>";
}
$results = "<table border=4 cellpadding=5 cellspacing=55 rules=all
frame=box style='table-layout:fixed;'>";
$results .= "<tr><th>Name</th><th>Number</th></tr>";
}
$results .= "</table>";
$results;
retrieve number:
<script type="text/javascript">
var cusn;
$(document).ready(function(){
$("#e1").click(function() {
cusn = $(this).attr('id');
alert(cusn); // this always returns e1
});
});
</script>
Ajax Call
<script type="text/javascript">
$(document).ready(function(){
$("#e1").dblclick(function(e) {
$.post("testClickcallback.php",
{"custnum":cusn}, function getCustNo(id)
{
cno = 'cust'+id;
cnm = "name"+id;
cname = document.getElementById(cnm).innerHTML;
cnum = document.getElementById(cno).innerHTML;
alert("For customer "+cname+" the number is "+cnum);
return;
}
// alert("subval");
//alert(subval);
,"html");
});
});
</script>
// receive error: document.getElementById(...) is null
Callback function:
<?php
$json = Array();
$json['custnum'] = $_POST['cusn'];
echo json_encode($json);
?>
//response:
|
||Notice: Undefined index: cusn in /var/www/testClickcallback.php on line 5
||
||Call Stack:
|| 0.0005 126856 1. {main}() /var/www/testClickcallback.php:0
||
||
||Variables in local scope (#1):
|| $json = array ()
||
||{"custnum":null}
Now what??|||||
Ethan
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php