Page 1 of 1
Javascript or PHP?
Posted: Sun Aug 04, 2002 10:02 pm
by Indium
I am trying to setup two dropdown menus where the selection in one menu dynamically sets the selection in the second dropdown menu. This seems like a situation where javascript would be the best way to go, but is it??
If someone has javascript disabled then it would not work. On the other hand would a php script be slower than a javascript since the server would be involved with the php option? Lastly, if javascript workarounds are needed in order to get the script to work in various browsers would php be any better in that regard? Need some direction.
Thanks.
Posted: Sun Aug 04, 2002 10:17 pm
by EricS
This question will very from programmer to programmer but I'll give you my two cents.
I always try to make my sites javascript independant. For the very reason you pointed out, not every browser has javascript enabled, and I've recently ran into problems with javascript and IE6.0 which is not good considering XP is selling like hot cakes.
As far as speed, the difference in speed between PHP and Javascript will probably be inperceptable, depending on the server your running on and how efficiently you write the code. Remember speed was at the heart of PHP from it's inception.
So my vote is PHP!
Posted: Mon Aug 05, 2002 1:33 am
by twigletmac
I vote server-side because I can't control what users do with their browsers or what browser they use but I can configure my server pretty much any way I like. However, I've never been much of a fan of Javascript (I work in the public sector where accessiblity is very important) so I'm biased.
Mac
Posted: Mon Aug 05, 2002 1:42 am
by gnu2php
Why not use both? You could have the people without JavaScript use PHP.
Here's some sample JS code (tested in NS 3.0 and 4.5; IE 6.0; and Opera 6.0):
Code: Select all
<form name="myform" action="sync_menus.php">
<select name="list1"
onChange="document.myform.list2.selectedIndex =
this.selectedIndex">
<option>Red
<option>White
<option>Blue
</select>
<select name="list2"
onChange="document.myform.list1.selectedIndex =
this.selectedIndex">
<option>Red
<option>White
<option>Blue
</select>
<noscript>
<!-- Submit button only visible for non-JS browsers -->
<input type="submit">
</noscript>
</form>
Posted: Mon Aug 05, 2002 1:06 pm
by EricS
The problem I have with coding for both is that it's twice the work when doing it once in php would fix the problem. And like I said before, I've been running into alot of sites that now have Javascript errors that never had them before, and when I go to another computer running IE 5.5 (instead of 6.0) I don't get the error. Anyway, just my two cents.