I have created timer using javascript and its not working for the input value That I want instead its setting directly to 0 seconds just after submiting the form
here is my javascript code for countdown timer
Here In my form $num_questions contains a value of no.of questions user have entered through form , Basically the timer should be set for the value entered by user in no.of questions field but instead its is directly come to 0:00 just after clicking submit the form and redirect to form , I cant understannd how to fix this .
How can I fix it?
Check the page source for what PHP is assigning to seconds.
Also, currently setInterval doesnât run, and the function only runs once.
Thatâs because you arenât supposed to instantiate a function when using setInterval.
@Paul_Wilkinsits hey I checked that and its just taking the input value which is entered by user through form field named no.of questions which is stored in a variable name $num_question i.e if I entered no.of questions = 6 then its just showing âDuration : 6â but not setting timer for 6 minutes, How can I check it? I am confused a bit
@Paul_Wilkinsits yes, but then I edited the line
var countdownTimer = setInterval(secondPassed(), 1000); and made it like this
var countdownTimer = setInterval(secondPassed, 1000); but its still setting to 0:00 directly and redirecting to my form
How can I correct it then?
In case you werenât aware, the webpage source code is partly different from the code that you edit in your editor.
You can right-click on the webpage and select âView page sourceâ to obtain that.
It is that page source code that I am asking you for, which we havenât received here yet.
Okk Thanks a lot . Its working now actually I removed the line of var seconds and put it in my output form code and then its working properly, but thanks for yor help, I also learnt some new thing from this conversation.
@Paul_Wilkinsits hey sorry too bother you again , but the timer is again showing the same failure but ths time its working for $num_questions but instead when I assign var secons to anothe variable named $duration (duration is my other form field like questions), and I just chnged the nme there and its showing the failure again , and I checked the pgp source code also its just as same as it was for the $num_question.
When you assign a number to a form field, the form converts it to a string.
Without seeing what youâve been doing, itâs a fair bet that when you retrieve duration from the form, that itâs a string and should be converted to a number.
@Paul_Wilkinsits this is my code where I have declared $duration in the div tag whose id is countdown, and my javascript code for timer is same as it was before which I have mentioned in above post