-1

I am trying to offer font size selection for accessibility purposes on my website. When the user clicks for example the small "A", it POSTS font-size=small in the URL.

Then, an if statement GETs the font-size and I would like to change the entire page:

<?PHP

$font_size = $_GET['font-size'];

if ($font_size=="small"){

  //this is incorrect and does not work
  document.body.style.fontSize='x-small';
}

?>

The HTML code below successfully changes the font size across the whole page, so how do I do the same thing in the PHP IF statement above?

<a href="#" onclick="document.body.style.fontSize='x-small';"> A </a>

Help is greatly appreciated.

  • 3
    Does this answer your question? [What is the difference between client-side and server-side programming?](https://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming) – B001ᛦ Feb 12 '20 at 15:14
  • @B001 I understand how this is relevant but is it not possible to execute the "onclick" code if an IF statement is met instead? – Kurtis Dunphy Feb 12 '20 at 15:18
  • Sorry but I'm not able to understand your question in the comment above.. what does conditions have to do with onlcik events? I think your are confusing things – B001ᛦ Feb 12 '20 at 15:22
  • if you want to refresh the whole page just to change the font then you can do it though the way you have done it but if you dont want the user to refresh the page then id recommend looking to do it in Javascript. what are you trying to do? – Curtis Northam Feb 12 '20 at 15:23
  • @CurtisNortham refreshing the page is fine. When the page loads I would like to increase/decrease the font fize depending on what size has been posted to the URL. That is, if the url reads Home.php?font-size=large then the page will refresh and document.body.style.fontSize='x-large'; – Kurtis Dunphy Feb 12 '20 at 15:37
  • try doing this `$( document ).ready(function() { document.body.style.fontSize='x-small'; });` in the if statement because normally you'd have to do this in javascript and client side scripting and server side scripting are different – Curtis Northam Feb 12 '20 at 15:43
  • within the PHP `if` statement you could echo a ` – ADyson Feb 12 '20 at 15:53

1 Answers1

1
<?php

  $font_size = $_GET['font-size'];

  if ($font_size=="small"){
   echo "<script>document.body.style.fontSize='x-small';</script>";
  }
?>

Here you go! you can't run javascript directly in PHP.