This question already has an answer here:
function myfun(){
var texteld= document.getElementById('texteld').value;
<?php
$id = "<script>texteld</script>";
}
This PHP and JavaScript code does not working. i want to pass java script texteld value to PHP $id
</div>
To Answer your question, you need to understand how a page loads:
So, as you can see, php is run before javascript is even sent to the browser to be run. What you want to do is go backwards in the process, this is not possible.
After the page loads and the browser has some data, you can send data back to php. This is not the same as your attempt though. You may need to rethink your strategy.
To pass a Javascript value to PHP you'd need to use AJAX. With jQuery, it would look something like this (most basic example possible)
var variableToSend = 'foo';
$.post('file.php', {variable: variableToSend});
On your server, you would need to receive the variable sent in the post:
$variable = $_POST['variable'];
Or use This
function myJavascript() {
var texteld = document.getElementById('texteld').value;
window.location.href = "test2.php?name=" + texteld;
}
In php file get variable like these code
<?php
if(isset($_GET['name'])){
$name= $_GET['name'];
echo $name;
}
?>