Jump to content

Recommended Posts

Hi there, i would really appreciate some help on the following matter.  Been stuck for hours trying to do this simple process.

 

I have a php page, with includes a js page full of my functions.

On my php page i have a button which calls a javascript function from my js file parsing varibles.

All is good and happy.

I want to add a if statement at the bottom of my php page. 

If (myvalue == 1)

{

    (Run my function, the same one that is being ran on my button)

}

There is no click event or anything.. its just if by the end of my page that varible equals 1 i want the button to press without the user having to click it.

 

I have tried using jQuery, but to no luck.

 

Thanks in advance,

Duckstar

Link to comment
https://forums.phpfreaks.com/topic/182264-call-javascript-function-on-php-if/
Share on other sites

So that would go into my if command ?

Like so ?

 

if($numOfDrill == 1)

{

 

 

echo("<script type='text/javascript'>");

echo("$(document).ready(function()");

echo("{");

echo("alert('loaded');");

echo("});");

echo("</script>;");

 

 

 

}

 

Because this isn't working at the moment :(

I have included the jQuery.js at the top of my page.

I am not sure if it is correct to use all the echo's.

But if i don't use them, it errors on the first '<'

 

Cheers,

should be

 


if($numOfDrill == 1)
      {
      

         echo("<script type='text/javascript'>");
         echo('$(document).ready(function()');
         echo("{");
         echo("alert('loaded');");
         echo("});");
         echo("</script>;");

      
      
      }

Hi, This still isn't working for me..

I will quickly explain a little more about my php pages..

I have a main page, in which my .js files are added to the  $gsPageHeadInc

Then this page starts a java function which uses AJAX to display a php page in a div.

 

It is this page loaded up in the div which i want to include this if statement.

I copied the statement you posted above but it isn't working.

The if statement is working though as i can see a ";" appear.

I don't think the jquery function is being read properly

This is in my first php

$gsPageHeadInc = "<script language=\"javascript\" src=\"".$basepath."script/ssCalendar.js\"></script>\n";
$gsPageHeadInc .= "<script language=\"javascript\" type=\"text/javascript\" src=\"".$basepath."script/ajax_inv_check.js\"></script>\n";
$gsPageHeadInc .= "<script language=\"javascript\" type=\"text/javascript\" src=\"".$basepath."script/jquery.js\"></script>\n";

$gsPageHeadInc .= "<script language=\"javascript\"><!--\n";

This is in the php page loaded as a div

	if($numOfDrill == 1)
	{


         echo("<script type='text/javascript'>");
         echo('$(document).ready(function()');
         echo("{");
         echo("alert('loaded');");
         echo("});");
         echo("</script>;");



	}

 

I have double checked that the file is there..  located at

C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\TLCMain\script\jquery.js

 

Thanks again.

Duckstar

Sorry i don't understand.

I have blank divs in my main page, in which ajax fills with another php page on my functions.

So for instance.

(phpPage1)

When i run myFunction();

it goes to my ajax_inv_check.js,

runs the function picking up the different element values and then parses them to phpPage2 which opens in my phpPage1 div

It is phpPage2 which has the if statement which will load a function from my ajax_inv_check.js.

 

I think my brain is going to fry in a minute..

Cant find the edit post button.

 

Right i just copied the same if statement code but without the if to my main page and its working..

So my jquery is loading correctly..

Just need to find out why my phps loaded into div's aren't not picking up the jquery functions...

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.