Search
 
SCRIPT & CODE EXAMPLE
 

PHP

how to add javascript to a php file

//this is my code 

you can add javascript to your code by using the echo statement and rap all 
your javascript between "" and if there is "" in the javascript code
then add  before any "", and for the php inside rap it with ''
  
  
<?php
  echo "<script>document.write("hello world")</script>"
?>
  
//other example

<?php
  $a = 5;
  echo "<script>document.write('$a')</script>"
?>

//other example
  
<?php 
$TokenData = Auth::user();

echo "<script type="text/javascript">
             localStorage.setItem("id", '$TokenData->id');
             localStorage.setItem("name", '$TokenData->name');
             localStorage.setItem("email", '$TokenData->email');
      </script> ";
Comment

how to include javascript in php

// simply echo the path anywehre in php you need

echo "<script src="script.js" type="text/javascript"></script>"
Comment

PREVIOUS NEXT
Code Example
Php :: php sort array remove keys 
Php :: php artisan add row in table 
Php :: get file request in laravel 
Php :: laravel blade fontawesome 
Php :: use smarty variable in php 
Php :: laravel validation string type 
Php :: change default user table name laravel 
Php :: laravel using username instead of email 
Php :: nginx codeigniter remove index.php 
Php :: update checkbox value in laravel 
Php :: get the number of affected rows in php using pdo update statement 
Php :: Laravel nova resolveUsing 
Php :: IlluminateContractsContainerBindingResolutionException 
Php :: dependable validation in laravel 
Php :: php mail template 
Php :: laravel 6 make http request 
Php :: php check year and month is between two dates 
Php :: secure random number php 
Php :: php xml to json 
Php :: php query to hide duplicate records 
Php :: select2 on modal 
Php :: smarty switch case 
Php :: how to search like in php 
Php :: laravel Access to HMLHttpRequest from origin has been blocked by CORS policy: No Access-Control-Allow-Origin 
Php :: laravel mail cc 
Php :: Program for factorial of a number in php 
Php :: arc cosine php 
Php :: laravel how can I use the same foreign key twice in a single table 
Php :: how to get the size of an uploaded file in laravel 
Php :: laravel validation custom message example 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =