2


I have one form in PHP, i want when i submit form, post input value to jQuery.
Actually when click on submit button, post "refresh-time" to jQuery.

I'm grateful for help

<script>
    setTimeout(function() {
    window.location.reload(); 
    }, $refresh-time);
</script>

<form method="POST">
   <label>refresh number</label>
   <input type="text" name="refresh-time">
   <button type="submit">apply</button>
</form>
3
  • Get the post value first, $refresh_time = $_POST["refresh-time"], then you should echo the variable, like <?= $refresh_time ?>. validate the post var before getting it. Commented Mar 20, 2017 at 4:46
  • @Faiz99 Thanks for your help Commented Mar 20, 2017 at 4:59
  • Are you actually POSTing the form or purely using ajax/jquery without a page reload? Commented Mar 20, 2017 at 5:52

3 Answers 3

0

PHP can generate code javacript and html, and in php you can ECHO, PRINT all in your document, and IF you want give return value form php to java/jQuery is not problem

example:

<?php 
// this EXAMPLE POST, 
$time = $_POST['second'] * 1000; // convert milsec to sec
?>

<script>
    setTimeout(function() {
    // this place to use java code
    }, <?= $time; ?>); // use refresh variable 
</script>

i hope you understand, i recommend you for learning again for PHP (Sorry)

Sign up to request clarification or add additional context in comments.

2 Comments

perfect,Thanks for your help @Abdul Aziz Al Basyir
for perfect, please give rate for this answer @fanasasharif
0
<?php 
   //  refresh variable 
   $refresh_time = 1000;
?>

<script>
    setTimeout(function() {
    window.location.reload(); 
    }, <?= $refresh_time; ?>); // use refresh variable 
</script>

<form method="POST">
   <label>refresh number</label>
   <input type="text" name="refresh-time">
   <button type="submit">apply</button>
</form>

Comments

0
<script>
var refreshtime = <?= $_POST['refresh-time'] ?> || 10000;
    setTimeout(function() {
    window.location.reload(); 
    }, refreshtime);
</script>

<form method="POST">
   <label>refresh number</label>
   <input type="text" name="refresh-time">
   <button type="submit">apply</button>
</form>

i set 1000 as default value to use on first time. you have to read from $_POST array to access form submit values. then use tags echo to print on javascript code

1 Comment

your answer is concrete, in my opinion.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.