0

I wish anybody help me here, its very big problem for me.. I want to implement javascript into check_data.php but this is can't be done maybe becuase this page doesn't appear in the browser, index.php display table from check_data.php but for some reasons i need to implement javascript into check_data.php any help?

index.php:

  <input type= "text" name= "datepicker"  id="datepicker" class="form-control" />
   </div>

   <script>
   $('#datepicker').change(function () {

   $.post('check_data.php', {
     dtpickerdate : $(this).val()
   }, function (response) {

    $('table').html(response);

    });

 });

 $("#datepicker").datepicker({dateFormat: "mm-dd-yy",})
                 .datepicker("setDate", new Date()).change();

 </script>

Check_data.php

<table id = "table" class = "table table-bordered">

        <thead class = "alert-info">
         <tr>
                <th>Kitchen Time</th>

                <th>Order#</th>

                <th>First Name</th>
                <th>Last Name</th>
                <th>Address</th>
                <th>Driver#</th>
                <th>Delivery Time</th>
                <th># of People</th>
                <th>Miles</th>
            </tr> </thead><tbody>
  <?php
  $dtpickerdate = isset($_POST['dtpickerdate']) ? 
                        $_POST['dtpickerdate'] : NULL;

 $q_customer = $conn->query("SELECT * from orders inner
                  JOIN customer_order on 
               customer_order.order_no =orders.order_no
               and orders.date like'$dtpickerdate' inner join 
               driver_order  on 
               driver_order.order_no=orders.order_no
               LEFT JOIN customer on 
               customer.phone=customer_order.phone 
               order by k_time,time desc" )
 or die(mysqli_error());

 $k_time = '';
 while($f_customer = $q_customer->fetch_array()){
 $s=mysqli_num_rows($q_customer);
 ?>
  <tr>
 <?php   

    if($k_time == '' || $k_time != $f_customer['k_time']){
     $k_time = $f_customer['k_time'];
     echo '<td align="center" > <span style=" font-weight:bold;">' 
     .$f_customer['k_time']. '</td>';
      } else{
      echo "<td td style=' border: none;'>&nbsp;</td>";
      }
       echo "<td style='background-color: #5f5d5d; ' align='center'  span style='font-weight:bold;'> <a   href = '#' style='color:#ececec;font-weight:bold;' data-toggle = 'modal' data-target = '#action'>".$f_customer['order_no']."</a></td>";

   echo    "<td style='background-color: #5f5d5d;color:#ececec;'>" .$f_customer['first_name']."</td>"; 
  echo "<td style='background-color: #5f5d5d;color:#ececec;'>". $f_customer['last_name']."</td>";
   echo "<td style='background-color: #5f5d5d;color:#ececec;'>". $f_customer['address']."</td>";
   echo "<td style='background-color: #5f5d5d;color:#ececec;'>". $f_customer['driver_no']."</td>";
   echo "<td style='background-color: #5f5d5d;color:#ececec;'>".   $f_customer['d_time']."</td>";
   echo "<td style='background-color: #5f5d5d;color:#ececec;'>". $f_customer['no_ofppl']."</td>";
}
Vsauce Code
  • 13
  • 1
  • 7
  • Javascript runs in the browser - it doesn't care at all how you structure your PHP as it only sees the final output – JimL Jan 31 '17 at 16:53
  • I hate to be that guy, but I must. I will bluntly assume you are new to all of this, and if this is the case, you need to go back to the basics and do all of this properly, separate presentation, functionality and behaviour, merge them after, it will make up for the cleaner code. Back to the issue at hand though, as other members stated, JS is in the browser so you just need to give it a place to sit and wait for your HTML to come – Dellirium Jan 31 '17 at 16:55
  • 1
    Possible duplicate of [Call php function from javascript](http://stackoverflow.com/questions/7165395/call-php-function-from-javascript) – Kevin Kopf Jan 31 '17 at 16:56
  • Technically it kinda *does* appear in the browser, it's an AJAX response call so it *is* being read by JavaScript - and therefore the browser - just not on the screen you're looking at... – CD001 Jan 31 '17 at 16:57
  • please google before you post. This question had been asked like a million times – Kevin Kopf Jan 31 '17 at 16:57
  • check_data.php display table records but calls from index.php because Im using datepicker and when change datepicker date, its bring data from check_data, Im sorry because you hate me but I really need this help,all my project stop on implement javascript into check_data.php – Vsauce Code Jan 31 '17 at 16:59
  • as you see I don't use ajax in index.php ??? – Vsauce Code Jan 31 '17 at 17:00
  • When @Dellirium says *"I hate to be that guy, but I must"* ... that basically means he's apologising for what he's about to say - *not* that he hates you :) – CD001 Jan 31 '17 at 17:03
  • I assume what you're trying to do is load the HTML from `check_data.php` into a table on `index.php`, using AJAX, **when** the value changes in `` ? ... in which case, no, JavaScript won't run on the code output by `check_data.php` when you're reading it in with AJAX. – CD001 Jan 31 '17 at 17:06
  • yes its working fine but I need to implement javascript into check_data.php but no javascript code works because its nondirect page! – Vsauce Code Jan 31 '17 at 17:08
  • @VsauceCode then you need to return the code from that page m8, if you specifically need the code to be in that page. Echo a script tag if nothing else will work out for you, though best recommendation is to use AJAX. Javascript does not NEED to be in the `check_data.php` page in order to work on that page, it can be on anypage, so long as you load it into the browser – Dellirium Jan 31 '17 at 17:11
  • Yeah, that's not gonna work I'm afraid... it would if you opened `check_data.php` directly in the browser but an AJAX call will basically treat whatever it sees as plain text - it won't execute anything in `` tags. – CD001 Jan 31 '17 at 17:11

1 Answers1

0

Looks like you are trying to load the HTML into the page via ajax.

You can try jQuery.load():

page.php

$('table').load('check_data.php');

Edit: It seems like you are confused about the difference between JavaScript and PHP, and when/how to use each. However, to answer your question, you could put additional JavaScript into another file, and load that as well.

page.php

$('table').load('check_data.php', function() {
    $.getScript('alert.js');
});

alert.js

alert('hi');
BadHorsie
  • 14,135
  • 30
  • 117
  • 191
  • can I implement javascript into check_data.php? even if i want to echo alert("hi"); using javascript but how??? – Vsauce Code Jan 31 '17 at 17:05
  • Thank You @BadHorsie but the problem that I want to get name of order_no so I can modify or delete it as you see: and javascript code to do this is: – Vsauce Code Jan 31 '17 at 17:19