Page 1 of 1

HELP ASAP

Posted: Thu Nov 13, 2003 5:07 pm
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;

Posted: Thu Nov 13, 2003 5:24 pm
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.

Posted: Thu Nov 13, 2003 5:37 pm
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.

Posted: Fri Nov 14, 2003 8:00 am
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