SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Member
    Join Date
    Jul 2011
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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 ?

    Code:
        <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>

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,688
    Mentioned
    100 Post(s)
    Tagged
    4 Thread(s)
    All you should have to do is to set the sec variable to the new value.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Member
    Join Date
    Jul 2011
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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 ?

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,688
    Mentioned
    100 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by czezz View Post
    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.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    SitePoint Member
    Join Date
    Jul 2011
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  6. #6
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,688
    Mentioned
    100 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by czezz View Post
    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.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  7. #7
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,495
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by czezz View Post
    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 ?
    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.

  8. #8
    SitePoint Wizard bronze trophy C. Ankerstjerne's Avatar
    Join Date
    Jan 2004
    Location
    The Kingdom of Denmark
    Posts
    2,702
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    You will need to do this:
    Christian Ankerstjerne
    <p<strong<abbr/HTML/ 4 teh win</>
    <>In Soviet Russia, website codes you!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •