Need help show/hide input field using $.post

Need help show/hide input field using $.post

Hey guys. I have been racking my brains out to get  this small function to work for the past 2 days. I tried every single thing I can possible think of and it still isn't working!! :(

What I'm trying to do, is show an input field if a php property($is_delivery) is set to true. Initially it is set to false.
When the  drop down option is set to  "Delivery" an ajax post needs to set it to true and display the text field.

Also FYI. If you guys are wondering why can't I just use show/hide... It because in my real world application is because the session starts off as false if they decide the change their order to delivery it needs to override the property to 1 and display the form.

Here is how it starts out. There are 3 pages.
jquery.php - The page that shows/hide the address input field if "Delivery Option" has been selected
testing_class.php - That page that is included in jquery.php that initially sets that value to false.
ajax.php - The page that is called by ajax and set the is_delivery to true.


testing_class.php


  1. class Testing {

    public static $is_delivery = false;

    }





jquery.php

  1. include'testing_class.php';
    var_dump(Testing::$is_delivery);
    ?>
    <script src="jquery.js"></script>



    <script type="text/javascript">
       
    $(function() {

    $("#delivery_method").change(function() {
        if($(this).val()== "Pick Up") {
        $("#address").hide();

    } else {
       
      $.post('ajax.php');
       $("#address").show();
    }
     
    });// end of $("#delivery_method").change(function(event) {


    });// end of $(function() {


    </script>


    <select id="delivery_method">

    <option selected>Pick Up</option>
    <option >Delivery</option>

    </select>
    <?php if(Testing::$is_delivery ) { ?>
    <?php echo "<input type=\"text\" id=\"address\">" ?>
    <?php } ?>








































ajax.php page



  1. Testing::$is_delivery = true;

    $firephp->fb(Testing::$is_delivery); //  I have tested this with fire php and returns 1 on the console.... so it obviously working