0

I have a text that i inserted with js to an element. Is there any way to get that element text with php and store it in a variable?

$('.text').text(e['title']);
<div class="text"></div>
<?php
$text = ...?
?>
Vander
  • 79
  • 9
  • 2
    Does this answer your question? [What is the difference between client-side and server-side programming?](https://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming) – freedomn-m Oct 09 '20 at 11:14
  • 1
    @freedomn-m so that means i can't get it? because it runs in the server before the js works? – Vander Oct 09 '20 at 11:19
  • 2
    Consider a letter. You write your letter, then send the letter to your mum via post. She then writes all over it to correct all your bad grammar (:)). Without sending it back, you can't see what's she's written. You're php, your mum is javascript and the postal service is the http request Edit: maybe a better analogy would be an invite to dinner asking what she'd like :) You don't know what she's written until she sends it back in a "POST" request. – freedomn-m Oct 09 '20 at 11:22

1 Answers1

2

As mentioned before, you need to understand the difference between server side and client side.

Your web browser (HTML and Javascript, your client side languages) need to send the value to the server, then PHP (the server side langage programming) can deal with it. You can use forms to send data to the server. See https://www.php.net/manual/en/tutorial.forms.php where there is some simple exemple

If you want the data to be sent without user interaction, you can use ajax with jquery https://api.jquery.com/jquery.ajax/ (or vanilla ajax without jquery)

magrigry
  • 405
  • 2
  • 8