如何激活特定的PHP包括

I have many PHP includes on my webpage; I don't want them active until a button is clicked or someone hits enter.

AND then I would like to call the specific DIV ID [php include] and not all of them on the page.

I have an input field that the user would enter a zip code, then hit the go button or enter key, after that happens; I would like the script to activate the php include for that div ID.

For example: I have a - div id="zip60538" - that has a php include - [include myfile.php]

which I don't want activated on page load, I only want the DIV ID php include activated after the go button or enter is hit.

There will be a 100 div id's with PHP includes so I would like to be specific and only fire the matching DIV ID PHP Include and not all of them on the page. Each DIV is setup as zip(then the actual zip code) so zip60538 is the div ID and the user would enter 60538 in the input field.

What I was thinking is: 1. look at input box 2. if zip+(input box values) matches 3. then activate my.php include, in div id zip60538

is that possible?

 $(document).ready(function(){
var zipCodes   =[60538,60504,75001,76008,75002,75013,76009,76225,75409,76226,76001,76002,76006,76010,
76011,76012,76013,76014,76015,76016,76017,76018,76227,76020,75413,75180,75101,76021,
76022,75414,76126,75424,75418,76023,76028,75135,75006,75007,75010,76127,75104,75423,
75009,75105,76031,75211,76034,76233,75121,75019,75114,76035,76036,];
$("#buttontest").click(function(){
 var zipIndex = zipCodes.indexOf(parseInt($("#full_day").val()));
 $("#zipMessage > div").hide("fast");
 var zipId = zipIndex > -1 ? zipCodes[zipIndex] : "Error";
$("#zip"+zipId).show("fast");
});

$("#full_day").keydown(function(e){
  if(e.which === 13){
     $("#buttontest").click();
}
});
});

http://jsfiddle.net/7SPGh/35

PHP runs on the server and by the time the browser loads your web page, PHP has "already done its thing" and can no longer hold an open conversation with the browser.

That being said, your best option here is to use AJAX. And in keeping things as simple as possible, I recommend using jQuery's .ajax() method.

This way, once a user takes an action, you can handle that event using JavaScript, call something from the PHP on the server, and return it back to the browser for use (essentially creating an open conversation between the browser and the server).

An example would look like this:

$("#some_button").on('click', function(e) {
    $.ajax({
        type: 'POST',
        url: 'some_php_script.php',
        data: {foo : "bar"}
    })
    .done(function(results) {
        // check to see if results is actually html
        // going to assume it is for the sake of example
         $("#zip60538").html(results);
    });
});

You mentioned you have hundreds of separate includes, so creating a basic function that takes arguments and abstracts this functionality would be best for your particular case. AJAX is the way to go. Good luck!