Vander
Vander

Reputation: 89

Insert text inserted with javascript to a php variable

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 = ...?
?>

Upvotes: 0

Views: 136

Answers (1)

magrigry
magrigry

Reputation: 427

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)

Upvotes: 2

Related Questions