1

I tried to create a timer based on the user input for how long the timer will go

here is my code for user input userinput.html

<form method="post" action="update.php">
<input type="number" name="inputnumber" />
<input type="submit" value="OK" />  
</form>

here is my code using javascript and php update.php

<script type="text/javascript">
function countdown(secs, elem){
        var element = document.getElementById(elem);
        element.innerHTML = "Please wait for "+secs+" seconds";
        secs--;
        var timer = setTimeout('countdown('+secs+',"'+elem+'")', 1000);
}
</script>
</head>
<body>
<div id="status"></div>
<script type="text/javascript">
countdown("<?php $test = $_POST['inputnumber'];?>","status");
</script>

</body>

I'm trying to pass the user input using php to javascript which is from this line

<script type="text/javascript">
countdown("<?php $test = $_POST['inputnumber'];?>","status");
</script>

I want the timer start based on the user input

but the result is the timer always start from 0

is my code wrong to passing the value from php to javascript ??

anyone know how to pass the value??

thanks

1 Answer 1

1

You need to echo the post parameter, otherwise it won't print for your JavaScript to use

countdown("<?php echo $_POST['inputnumber'];?>","status");

Or shorthand

countdown("<?=$_POST['inputnumber'];?>","status");
Sign up to request clarification or add additional context in comments.

Comments

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.