PHP vs JavaScript

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
kgenecole
Forum Newbie
Posts: 2
Joined: Wed Apr 26, 2017 9:40 am

PHP vs JavaScript

Post 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
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: PHP vs JavaScript

Post 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...
kgenecole
Forum Newbie
Posts: 2
Joined: Wed Apr 26, 2017 9:40 am

Re: PHP vs JavaScript

Post by kgenecole »

Yeah, I'm a little in doubt about what should remain client-side, and what should be php.
Post Reply