MythicalTomatoSoup Posted October 15, 2016 Share Posted October 15, 2016 Hey!I want to create a website that can test your counting pace. I’ll make colored, square div that change color after 10 to 30 seconds when you hover over it, and then you’ll type down how long you think it took in a form to check if you’re right.My solution to do this is to create the PHP variable $time = rand(10,30), and in CSS get the div:hover transition-delay to be $time. Then, after the form, I need the same variable for if($_POST[timeguess] = $time) {echo “Correct!”}.I have no idea how to access the same variable in both the CSS and HTML, so I hope some of you can help me out! Thanks Quote Link to comment https://forums.phpfreaks.com/topic/302343-how-to-access-a-php-variable-in-both-css-and-html/ Share on other sites More sharing options...
NotionCommotion Posted October 16, 2016 Share Posted October 16, 2016 Hello Mythical, The part you need to understand is that PHP lives on the server, and HTML/CSS/JS lives on the client browser. The only way to can use them on both is if you send the variables from one to another. One option is for PHP to create a web page and for PHP to echo your random time both within your CSS and within a hidden input. By echoing it, you are writing it or sending it from the server to the client. Then when the user fills out the form, both the hidden input and the timeguess input are posted or sent to the server. Some recommend not using PHP to dynamically generate CSS (or JS for that mater), and another alternative would be to echo an attribute such as data-time in you HTML, and use JS of the color changing. Good luck! Quote Link to comment https://forums.phpfreaks.com/topic/302343-how-to-access-a-php-variable-in-both-css-and-html/#findComment-1538327 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.