Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8579631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:38:59+00:00 2026-06-11T20:38:59+00:00

Ok , so what I’m trying to do is trigger PHP code, only when

  • 0

Ok , so what I’m trying to do is trigger PHP code, only when the if condition is true (in javascript) , I understand that php is server side, and javascript is client side. The include of the php code works perfect except 1 thing , it gets triggered on page load actually , not when the if condition happens. If you can help me how to do this will be rly appreciated. I want the php file to be included ONLY when the if condition is true

thanks in advance

here’s the code am using :

<html>
    <script src="//cdnjs.cloudflare.com/ajax/libs/visibility.js/0.5/visibility.min.js"></script>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript"></script>
<script>
var seconds=20;
var flag=false;


$(document).ready(function(){
if (!flag)
Visibility.every(1000, tick);



function tick()
{
      display();

        if (seconds>0)
        {
         seconds--;
        }
        else
        {
          if (!flag){
          document.getElementById('more').innerHTML +="<?php include_once('Code.php'); 
          ?>";
          document.getElementById('more').style.visibility='visible';
          flag=true;
          }
        }
}
function display()
{
   $("#timer").html(seconds);
}
});
</script>
<div id="TrafficHeader" style="height:100px; background-color:grey; padding:20px;">
<div id="timer"></div>
<div id="more" style="visibility: hidden;"><a href="http://www.double-it.com/Traffic/index.php">View Next Ad</a></div></div>
<iframe id="myframe" src="<?php echo ''.$URL;?>" height="100%" width="100%" frameborder="0">
</iframe>
</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T20:39:00+00:00Added an answer on June 11, 2026 at 8:39 pm

    This is not possible, at least not the way you are going about it.
    The reason is that the if condition is evaluated on the client machine long after the server finish evaluating your php script.

    First server has to finish procesing your php script, then imagine it has to pack it and then send the whole package to the client, which then unpacks it and renders the html and evaluates the javascript in html, or asks for external files like images, css or other script files.

    If you are trying to include some extra javascript ,than you can add extra script tag in the head programatically. If you want to do something on the server, you can call a script on a server just as easily.

    Here is how you can exeecute that script from javascript only if the if is true:

    ...
    if (!flag){
        xmlHttp = new XMLHttpRequest();
        xmlHttp.open( "GET", "http://link/to/your/code.php?and=special&parameters=sent", false );
        xmlHttp.send( null );
    
        document.getElementById('more').innerHTML += xmlHttp.responseText;
        document.getElementById('more').style.visibility='visible';
        flag=true;
        }
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.