Page 1 of 1

PHP vs JavaScript

Posted: Wed Apr 26, 2017 11:33 am
by kgenecole
Hi, I have a website that's built with JavaScript, but I'm wanting to take PHP now and build it again using the server-side language. I've used PHP to build me an interface to add items and manage them in a SQL database, but now that that's done, I've got to turn to the actual website. I have to admit I'm not sure how to convert some of the functionality I get with JavaScript into PHP. I can build the basic HTML page with PHP, but when it comes to the script code, I don't know how I can get the same effect using PHP. I have a simple function to display my category menus, and I'll quote it here so if someone wants to take a look at it and make suggestions of how I can use PHP to get the same functionality, feel free to comment. Of course, JavaScript and PHP never the twain shall meet, but I wonder how I can use PHP in it's place. I may have to continue to use the JavaScript, I don't know. But feedback would be helpful. Here's my function:
function ToggleDiv(chk,sub){
var setMain=document.getElementById(chk);
var lastSet=document.getElementById(setPrev);
var setSub=document.getElementById(sub);
var lastSub=document.getElementById(subPrev);
if(sub=="blankDiv"){
lastSub.style.display="none";
}
lastSet.style.display="none";
setMain.style.display=setMain.style.display=="block"?"none":"block";
setPrev=chk;
setSub.style.display=setSub.style.display=="block"?"none":"block";
subPrev=sub;
}
Thanks,
Kevin

Re: PHP vs JavaScript

Posted: Thu Apr 27, 2017 5:31 am
by Celauran
This looks like the sort of thing you'd want to keep client side. It would be possible server side, but you'd need to submit some kind of request to the server and trigger a page reload to render everything anew. Doesn't really make a ton of sense. Right tool for the job and all...

Re: PHP vs JavaScript

Posted: Sat Apr 29, 2017 11:02 am
by kgenecole
Yeah, I'm a little in doubt about what should remain client-side, and what should be php.