I have three files a .php, a .html and a .js. How can I combine all three of them so that I can use the value of a variable set in php in JavaScript?
            Asked
            
        
        
            Active
            
        
            Viewed 1,622 times
        
    0
            
            
        - 
                    Learn about AJAX. – SLaks Jan 19 '17 at 17:41
- 
                    Depends on how they are linked together – RST Jan 19 '17 at 17:42
- 
                    Show your code. The HTML can probably go in the PHP page. The PHP variable could be echo'd to the JS as a variable `var php_var = '';`. PHP is not available once the page has loaded, if the PHP var needs to be dynamic you'll need ajax. – chris85 Jan 19 '17 at 17:42
- 
                    I'm so wondering why this question received an upvote just now which provided no code and showed no effort. – Funk Forty Niner Jan 19 '17 at 17:45
- 
                    1http://stackoverflow.com/questions/23740548/how-to-pass-variables-and-data-from-php-to-javascript – Kevin Davis Jan 19 '17 at 17:45
- 
                    ^ that, being the duplicate I was looking for. – Funk Forty Niner Jan 19 '17 at 17:46
1 Answers
0
            
            
        I will have to save this file by .php extenstion
<html>
<head> </head>
<body>
 <?php
   // here I can write my php code ?> // I can end it any time to include some JS code here 
<script> Some js code</script>
<?php // and start again to write some more php code 
?>
</body>
</html>
 
    
    
        Mitesh Pant
        
- 524
- 2
- 15
