JavaScript - input box

This code display count down time to refresh current webpage.
The counter value is hardcoded to 10 seconds.
How can I add “input box”, that would be displayed right next to counter, to be able to change value ?


    <html>
    <head>
    <script type="text/javascript">
    var sec=10;
    function time() {
    if(sec==0) {
    window.location.reload(true)
    } else {
    sec--;
    document.getElementById('tm').innerHTML=(sec < 10) ? ("0" + sec) : sec;
    setTimeout("time();", 1000);
    }
    }
    </script>
    </head>
    <body onload="time()">
    Time to refresh:
    <span id="tm">10</span>
    </body>

All you should have to do is to set the sec variable to the new value.

According to similar thing which I can do in PHP, probably I need more:

  • input type “text”
  • input type “submit”

The thing is that I dont know how to do that with JavaScript.
Any help ?

Are you looking for someone to do the work for you, or do you want us to help you learn how to do it.

Well, I have no JavaScript experience at all.
Im trying to learn by examples. (as I did with PHP).

I believe that this one is not really sophisticated to avarage JS coder.
If that is too much for u or u cant help then please dont post anymore.

It’s important for me to ask, because we volunteer here to help people learn, but instead people expect us to complete their homework for them, or to do work for people who have no interest in learning how to code.

That’s not what we’re here for. Or at least, it’s not what I’m here for.

If you are interested in learning then well and good. If it’s for something else, then someone else might come along who will code up the exact solution that you’re looking for, so that you don’t have to do any learning.

Blame it on a bad case of the flu that I have right now.

You don’t do that with javascript. It’s a form, and it’s HTML. It has nothing to do with PHP or javascript.

The only difference between PHP and JS is, that if you want the form to send its values to a JS function, you’ll have to add some JS code somewhere in the form. Just google for ‘javascript form tutorial’ or something like that and I’m sure you’ll find lots of examples.

You will need to do this:

[list][]Add the input element.
[
]Set up your script to use the input element’s value for the timer (see How to get the value of a form element using JavaScript to learn how).
[]Set up your script so that it appends the value to the refreshed page’s URL.
[
]Set up your script so that it fills out the input element’s value with the value in the URL (see Get URL Variables - JavaScript - Snipplr Social Snippet Repository to learn how).[/list]