DataSpy Posted July 11, 2011 Share Posted July 11, 2011 I have a search form (phone or name), the search form is submitted with an onblur and then processed by php and returned to the same page with ajax. In the original page (index.php) I include a file (add_reservation.php) which holds the Search form, the output of the search for goes to a div with the results from ajax. I'm not even sure if this is possible or if I'm going about this the right way but what I want to happen is when the search form is submitted I want to hide the included file (add_reservation.php) because I don't want two tables to show up with with search form and results. you can see an example of what I'm talking about @ www.data-spy.net/test/ type 000-000-0000 into the phone field or type bank into the name field and tab through both input boxes, the result creates a second table (and an output of my sql query) which is the one I want to keep since the previous table has no data in it, if neither field is filled out it just echos back the sql query. Index.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Reservations</title> <script type="text/javascript" src="jquery-1.6.2.js"></script> <script> function get_customer_info() { $.post('get_customer_info.php', { customer_number: $('form[name=add_reservation_form] input[name=number]').val(), customer_name: $('form[name=add_reservation_form] input[name=name]').val() }, function(output) { $('#number_div').html(output).show(); }); } </script> </head> <body> <?php require("add_reservation.php"); ?> <div id="number_div"></div> </body> </html> add_reservation.php <?php echo' <form name="add_reservation_form"> <table width="50%" border="1" align="center"> <tr> <td colspan="2" align="center"> Search </td> </tr> <tr> <td> Phone </td> <td colspan="2"> <input type="text" name="number" size="22"/> </td> </tr> <tr> <td> Name </td> <td colspan="2"> <input type="text" name="name" onblur="get_customer_info();" size="22"/> <input type="hidden" name="submitted" value="yes"/> </td> </tr> <tr> <td colspan="3" align="center"> Customer Info </td> </tr> <tr> <td> Home </td> <td> </td> </tr> </table> </form>'; ?> get_customer_info.php <?php require("config.php"); require("dbconnect.php"); $customer_number = mysqli_real_escape_string($con, trim($_POST['customer_number'])); $customer_name = mysqli_real_escape_string($con, trim($_POST['customer_name'])); if(!empty($customer_name)) $customer_name = "%$customer_name%"; else $customer_name = $customer_name; $query_get_customer_info = "SELECT customers.customer_homenumber, customers.customer_email, customers.customer_firstname, customers.customer_lastname, customers.customer_address, customers.customer_zipcode, cities.city_name, states.state_name FROM customers LEFT JOIN cities ON customers.customer_city_id = cities.city_id LEFT JOIN states ON customers.customer_state_id = states.state_id WHERE customer_lastname LIKE '$customer_name' OR customer_homenumber = '$customer_number' OR customer_mobilenumber = '$customer_number' OR customer_worknumber = '$customer_number'"; $result_get_customer_info = mysqli_query($con, $query_get_customer_info) or die(mysqli_error($con)); $num_rows = mysqli_num_rows($result_get_customer_info); if($num_rows == 0) { echo $query_get_customer_info; } else { while($row = mysqli_fetch_array($result_get_customer_info)) { echo" <form name=\"add_reservation_form\"> <table width=\"50%\" border=\"1\" align=\"center\"> <tr> <td colspan=\"2\" align=\"center\"> Search </td> </tr> <tr> <td> Phone </td> <td colspan=\"2\"> <input type=\"text\" name=\"number\" size=\"22\"/> </td> </tr> <tr> <td> Name </td> <td colspan=\"2\"> <input type=\"text\" name=\"name\" onblur=\"get_customer_info();\" size=\"22\"/> </td> </tr> <tr> <td colspan=\"3\" align=\"center\"> Customer Info </td> </tr> <tr> <td> Home </td> <td> $row[customer_homenumber] </td> </tr> </table> </form>"; } echo $query_get_customer_info; } ?> Any help greatly appreciated, thanks in advance!!!!!!!!!!!! Quote Link to comment https://forums.phpfreaks.com/topic/241718-need-help-confuesed-hide-form-possible-solution/ Share on other sites More sharing options...
DataSpy Posted July 11, 2011 Author Share Posted July 11, 2011 I accidentally posted this in the wrong forum, this is a jquery question not an ajax question. Quote Link to comment https://forums.phpfreaks.com/topic/241718-need-help-confuesed-hide-form-possible-solution/#findComment-1241490 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.