xwishmasterx Posted October 26, 2013 Share Posted October 26, 2013 I have part of code as shown below: newdiv.innerHTML = "<a href=\"javascript:;\" onclick=\"removeElement(\'"+divIdName+"\')\"><div style='position:relative;top:5px;left:980px'><img src='luk.png' style='position:absolute' height='50' width='50'></div></a><div align='center'>THIS IS SHOWNG FINE</div> Basically clicking a link will show "THIS IS SHOWING FINE". I want it include som php instead like <?php include "myfile.php"; ?> How can this be achieved? Quote Link to comment https://forums.phpfreaks.com/topic/283306-adding-php-in-javascript/ Share on other sites More sharing options...
Irate Posted October 26, 2013 Share Posted October 26, 2013 JavaScript and PHP do completely different things. PHP works as hypertext preprocessor (hence its name, "PHP: Hypertext Preprocessor") and does not generate any events in the browser, it just helps to dynamically display content by querying databases or by checking unique identifiers given. JavaScript is client-side and gives you options to modify the document content, send asynchronous HTTP requests and generally does not provide dynamic content (unless you send, as mentioned before, HTTP requests). If the file you want to include contains pieces of JavaScript and you set the HTTP Content-Type to "application/javascript" (or for older browsers, "text/javascript"), you can do this. <script src="myfile.php" type="text/javascript"></script> Otherwise, you can echo content into the script tag itself. <script type="text/javascript"><?= $yourVariable ?></script> Quote Link to comment https://forums.phpfreaks.com/topic/283306-adding-php-in-javascript/#findComment-1455529 Share on other sites More sharing options...
xwishmasterx Posted October 26, 2013 Author Share Posted October 26, 2013 What I do not understand is basically the script just ouputs html code, why can't it simply output php?..but if it generally can't be done I'll look in some other direction..thanks for the reply. Quote Link to comment https://forums.phpfreaks.com/topic/283306-adding-php-in-javascript/#findComment-1455532 Share on other sites More sharing options...
Ch0cu3r Posted October 26, 2013 Share Posted October 26, 2013 (edited) What I do not understand is basically the script just ouputs html code, why can't it simply output php? Because PHP code is parsed on the server when the .php file is requested. Browsers can only parse client side code such as html, javascript and css. Edited October 26, 2013 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/283306-adding-php-in-javascript/#findComment-1455556 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.