-6

For example i have a variable

var test = "done";

how can I send it to php? and then post it

4
  • 1
    Submit a form? make an XMLHttpRequest? Make a GET request? Commented Jun 21, 2018 at 14:56
  • AJAX is the term you want to Google Commented Jun 21, 2018 at 14:57
  • Thanks I'll look into that Commented Jun 21, 2018 at 14:58
  • 1
    Possible duplicate of Javascript function post and call php script Commented Jun 21, 2018 at 15:00

1 Answer 1

0

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'];
?>
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.