I THINK there’s a very simple solution for my questions; I just haven’t learned how to do it yet. Let me break it into three steps:
- Consider this link to a JavaScript file in a web page’s head section:
The key code is <?php echo $unit ?>
-
Put the entire head section in a PHP include page.
-
On the target page, substitute a value for $unit and include the head section with the JavaScript link…
Another example…
<?php $seg = '../../../'; $unit = 'weight'; include ($seg."a1/inc/head.php") ?>It works just fine; I have four identical pages with included PHP head sections that use the $unit variable to fetch JavaScript four different JavaScript conversion files that focus on length, area, weight and volume.
But I want to convert them to just ONE page that works with all four units. I think I need to simply make links that somehow toggle the $unit value between length, area, weight and volume.
Tentatively, I’d like it to look like this…
Choose a Unit:
Length | Area | Weight | Volume
(Length, Area, Weight and Volume would be linked.)
But I don’t know how to do it. I’m not even sure if I want to make PHP or JavaScript toggle switches. I’ve read many warnings that JavaScript functions are rendered useless if visitors use browsers with JavaScript disabled. On the other hand, many people claim JavaScript is superior to PHP because the latter requires the page to be refreshed. On the other hand, I’m not sure if refreshing the page is really a big deal in this case; it’s a very small page.
At any rate, can someone tell me how to make toggle switches - or some function - that will get the job done?
Thanks.