Re: Ajax

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2/19/2013 12:16 PM, Ethan Rosenberg, PhD wrote:
Dear List -

With the INFINITE  THANKS to Jim Giner who provided me with the help to
get me out of the forest.

The customer db is

+----------+----------------------+------+-----+---------+-------+
| Field    | Type                 | Null | Key | Default | Extra |
+----------+----------------------+------+-----+---------+-------+
| Cust_Num | smallint(5) unsigned | NO   | PRI | NULL    |       |
| Fname    | varchar(25)          | NO   |     | NULL    |       |
| Lname    | varchar(25)          | NO   |     | NULL    |       |
| Street   | varchar(25)          | NO   |     | NULL    |       |
| City     | varchar(25)          | NO   |     | NULL    |       |
| State    | varchar(2)           | NO   |     | NULL    |       |
| Zip      | mediumint(9)         | NO   |     | NULL    |       |
| Phone    | int(10)              | NO   |     | NULL    |       |
| Date     | date                 | NO   |     | NULL    |       |
| Notes    | text                 | YES  |     | NULL    |       |
| P1       | int(3)               | YES  |     | NULL    |       |
| P2       | int(3)               | YES  |     | NULL    |       |
| P3       | int(4)               | YES  |     | NULL    |       |
+----------+----------------------+------+-----+---------+-------+

The credit db is:

+----------+----------------------+------+-----+---------+-------+
| Field    | Type                 | Null | Key | Default | Extra |
+----------+----------------------+------+-----+---------+-------+
| Cust_Num | smallint(5) unsigned | NO   | PRI | NULL    |       |
| Fname    | varchar(25)          | NO   |     | NULL    |       |
| Lname    | varchar(25)          | NO   |     | NULL    |       |
| Street   | varchar(25)          | NO   |     | NULL    |       |
| City     | varchar(25)          | NO   |     | NULL    |       |
| State    | varchar(2)           | NO   |     | NULL    |       |
| Zip      | mediumint(9)         | NO   |     | NULL    |       |
| Phone    | int(10)              | NO   |     | NULL    |       |
| Date     | date                 | NO   |     | NULL    |       |
| Notes    | text                 | YES  |     | NULL    |       |
| P1       | int(3)               | YES  |     | NULL    |       |
| P2       | int(3)               | YES  |     | NULL    |       |
| P3       | int(4)               | YES  |     | NULL    |       |
+----------+----------------------+------+-----+---------+-------+

What the customer wants - pardon, but I cannot display a table

Jones Tom 123 Street Leah; David, Malka
Jones, Sam 341 Street Sarah; Shira, Mordechai

Last Name, First Name, Address, Spouse; Persons authorized to charge.

He wishes to select which "Jones" to use, and then click on "Jones".

This will extract the Cust_Num, as cno  which [hopefully] I can do
constant $Cust_Num = $cno;

He will then be shown the credit history of the customer and asked if he
wishes to continue.  If yes, he will be give the option of credit or
payment.

$Cust_Num will be used in all the following calculations.

The program gives an error in the callback function:

|Notice: Undefined variable: cno in /var/www/testClickcallback.php on
line 9
||
||Call Stack:
||     0.0006     130112   1. {main}() /var/www/testClickcallback.php:0
||
||
||Variables in local scope (#1):
||   $cno = *uninitialized*
||   $json = array ('cnum' =>  NULL)
||
||{"cnum":null}|

The Error Console shows no errors.

Do you know any way I can cleanup my Ajax and make it work?

  Here are the scripts I am using:

testclick5.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
<html>
<div id="main">
<?php
     // make up some data in arrays here
     $names =
array("Jim","Joe","Stu","Ethan","Adam","Linda","Mary","Alice","Ann","Jeanne");

     $nums = array(1,5,4,99,23,45,64,84,91,25);
     global $cnum;
     $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='cust$k' id='nums$k'>$nums[$k]</td></tr>";

     }
     $results .= "</table>";
     $results;
     DisplayPage();
     MakeCustIndx();

?>
</div>
<?php

     function MakeCustIndx()
     {
         global $cnum,$cno;
?>
<link type="text/css" href="jquery-ui-1.8.9.custom.css" rel="stylesheet" />
<script type="text/javascript" src="jquery-1.6.2.min.js"></script>
<script type="text/javascript"
src="jquery-ui-1.8.10.custom.min.js"></script>
hello
<script type="text/javascript">
     var cusn;
     $(document).ready(function(){
         $("#main").click(function() {
             cusn = $(this).attr('id');
         });
     });

     $(document).ready(function(){
             $("#main").dblclick(function(e) {
                  $.post("testClickcallback.php",
                    {"custnum":cusn},  "html")

                 });
             });
</script>
<?php
     }
?>
<div id=m2>
</div>


<?php

     exit();
//******************************************
function DisplayPage()
{
     global $results;
     $code=<<<heredocs
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
      "http://www.w3.org/TR/html4/strict.dtd";>
<html>
<head>
<title>Get Customer Number</title>
<script type="text/javascript">
     var cno;
     var cnm;
     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;
     }
</script>
     $results
</body></html>
heredocs;
     echo $code;

}

testClickcallback.php

<?php

$json = Array();
$json['custnum'] =  $_POST['cusn'];
echo json_encode($json);
?>


Thanks for everything.

Ethan

Ethan - this can't possibly the code you are running. Your 'page' is a bunch of badly formatted html. YOu have a <head> tag but no end tag. YOu have an end body tag, but no start body tag. You have the html 'doctype' line being output twice. And on and on.

People don't need to see table layouts. People don't need to see examples of code that are clearly flawed on the outside.

You need to trust in php error messages. The error message (if it is EXACTLY what you say it is) tells you that at that specific point the var is unknown. Where is line 9?? Just as a guess, are you doing a .= to add some data to it, and it hasn't already been declared?

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux