Jump to content

adding php in javascript?


xwishmasterx

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/283306-adding-php-in-javascript/
Share on other sites

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.