try with this code
<script>
var test = "done";
document.getElementById('sample').value = test;
</script>
<form method = "post">
<input type="hidden" id="sample" name="stext">
<input type="submit" name="submit" value="submit">
</form>
<?php
echo $_POST['stext'];
?>
solved How do I send a variable from a javascript to a php file? [closed]