HELP ASAP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ericsodt
Forum Commoner
Posts: 51
Joined: Fri Aug 22, 2003 12:12 pm
Location: VA

HELP ASAP

Post by ericsodt »

I am trying to call a PHP function from javascript and am having NO luck... has anyone solved this before??

Code: Select all

//This is javascript  
function changeTab(mgObj){
  // Making all background colors blue
  for(i=0; i<tabs.length; i++)&#123;
     tabs&#1111;i].style.backgroundColor = 'blue';
	 right&#1111;i].style.backgroundColor = 'blue';
	 left&#1111;i].style.backgroundColor = 'blue';  
  &#125;
   // Making the selected cells background black
	 right&#1111;mgObj.name-1].style.backgroundColor = 'black';
	 left&#1111;mgObj.name-1].style.backgroundColor = 'black';  
	 mgObj.style.backgroundColor='black';
  switch (mgObj.name)&#123;
    case "1":
	  exercises.style.display="none";
	  chest.style.display="";
	  break;
    default: 
	  exercises.style.display="";
	  chest.style.display="none";
	  break;   
  &#125;
  // here is where the div refresh should occur
  tabs.innerHTML = //PHP FUNCTION GOES HERE
  
&#125;
microthick
Forum Regular
Posts: 543
Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC

Post by microthick »

I don't know if you can do that, since the PHP is interpretted before the JavaScript is executed.

You might have to have PHP write out any data you need into JavaScript containers so that your JavaScript functions can use that info later in your div refresh.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

maybe echo all of that javascript in php; and then set a variable to be true or false.

Then later on in the php script, if the variable is true, just execute a function.

Try that.
User avatar
Saethyr
Forum Contributor
Posts: 182
Joined: Thu Sep 25, 2003 9:21 am
Location: Wichita, Kansas USA
Contact:

Post by Saethyr »

I had to do this exact thing for a project at work, mine does a DB pull using PHP and writes it , via echo to javascript array's which in turn are used to populate a form. I looked every where and this was the easiest way to do it.


Jason
Post Reply