Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Javacript Novice Reply To: Javacript Novice

#242457
I.m.learning
Participant

PHP is only going to get you so far.
You seem to know that PHP is server-side; you need to provide it for your users when the page loads. JavaScript is built into the browsers and are mainly client-side that can be run after a page loads.

If you require something that is to be run after a page loads; PHP fails every time. Most JavaScript are pre-written, you just need to call upon those codes.

JavaScript has a library called JQuery in which we can download it to our local environment, or link to it through various sources.
Many sites use
https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js”

As Shikkedielsaid, “it’s purpose-driven.”
Meaning, what are you looking to do?
What do you do with your PHP?

How about an example for both- for the time:

PHP you do what, create a variable, and use some code? Okay..

<?php
$t=time();
echo($t . “<br>”);
echo(date(“Y-m-d”,$t));
?>

So, as soon as the page loads, it’s there.

But what if you don’t want the time to be displayed as soon as the page loads?
What if we want the user to initiate it, at their own discretion? Well, that’s where JavaScript comes in. Let’s create a button the user clicks to initiate the code

<button type=”button”
onclick=”document.getElementById(‘time).innerHTML = Date()”>What’s the Time?</button>

As soon as the user clicks the button, the time is displayed.