-6

I am trying to use some PHP code within Javascript statement. Now the syntax is a bit confusing bcoz of the quotes and I am unable to test it locally (cannot directly test it on the server)

So could you please confirm if the following line of code is correct;

"<a href='<?php somePHPFunction(" + $(this).text() + '.doc",10000,1,0); ?>'>" +  $(this).text() + "</a>"

Basically I need the following after evaluation;

<a href="http://myServer.com/DocNum123.doc">DocNum123</a>

The PHP function will return the server side path and file name without the extension (http://myServer.com/someFile)

Also $(this).text() would return DocNum123

copenndthagen
  • 49,230
  • 102
  • 290
  • 442

1 Answers1

2

Hint: you can't.

PHP is server side. The code runs before the page is even sent to your browser. Javascript is client side. It is executed after the server sends you the page.

To get your code working would require to: - Run PHP code on the server, send you the page. - Run Javascript, "edit" the page - Request the server for another version of your page, now with the code.

You can, however, directly add it into your HTML.

Just use The file is at the location <?php SomeMethod(); ?>.

pikzen
  • 1,413
  • 1
  • 10
  • 18