Message from JavaScript discussions

October 2020

— Can you share the code in plain text? using pastebin or hastebin


function change(){
header("location: register.php");
<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
.box {
height: 100px;
width: 100px;
background-color: green;

<div class="box" onclick="my()">
<button>Click me</button>

function my() {
var trigger = <?php change(); ?>

— You cannot call a php function from javascript.

— Php is a server. It serves data via HTTP.

— Here you use javascript on the browser (client-side) to interact with the user

— Then what is the way

E.g. you have a file change.php that does what you need, with javascript you can dynamically retrieve the content and display it.


const change = async () => {
const response = await fetch('/change.php')
const text = await response.text()
document.querySelector('#content').innerHTML = text

Message permanent page

— Will I get my desired result

— I think so

— But..if you want to redirect to another location, you don't need php

— You can simply do location = 'register'

— Or you just use native HTML and do:
<a href="register.php">click this to register</a>