www.webdeveloper.com
Results 1 to 5 of 5

Thread: Need help with some code asap very important

  1. #1
    Join Date
    Mar 2011
    Posts
    12

    Post Need help with some code asap very important

    ok- here is the code I have:
    I need to get it working asap please help thank you
    <html>
    <head>
    <title>Assignment 9c Clock
    </title>
    </head>
    <body>
    <script type="text/javascript">
    var disp_field = document.getElementById("display");
    var radios = document.getElementsByName("format");
    var ampm;
    var format;
    var time;
    function run_clock(){
    date_inst = new Date();
    var hours = date_inst.getHours();
    var mins = date_inst.getMinutes();
    var seconds = date_inst.getSeconds();
    if (radios[0].checked){
    format = "12hour";
    if (hours > 12){
    hours -= 12;
    ampm = "P.M";
    }
    else{
    ampm = "A.M";
    }
    }
    else{
    format = "24hour";
    }
    if (seconds < 10){
    seconds = "0" + seconds;
    }
    if (format == "12hour"){
    time = hours+":"+mins+":"+seconds+" "+ampm;
    }
    else{
    time = hours+":"+mins+":"+seconds;
    }
    disp_field.value = time;
    }
    var repeat = window.setInterval("run_clock()",1000);
    </script>
    <form>
    <div id="display"></div>
    <form>
    <input type="radio" id="format" name="format">format</input>
    <input type="radio" id="format" name="format">format</input>
    </form>
    </body>
    </html>

  2. #2
    Join Date
    Dec 2002
    Location
    St. Louis, MO, USA
    Posts
    1,582
    You have two opening form tags. It thinks you're trying to nest forms. Get rid of one of the opening form tags.

    ^_^

  3. #3
    Join Date
    Mar 2011
    Posts
    12
    ok, I did, but it still won't display anything

  4. #4
    Join Date
    Mar 2011
    Posts
    12
    here is my new code, but it will still not work-
    <html>
    <head>
    <title>Assignment 9c Clock
    </title>
    </head>
    <body>
    <script type="text/javascript">
    var disp_field = document.getElementById("display");
    var radios = document.getElementsByName("format");
    var ampm;
    var format;
    var time;
    function run_clock(){
    date_inst = new Date();
    var hours = date_inst.getHours();
    var mins = date_inst.getMinutes();
    var seconds = date_inst.getSeconds();
    if (radios[0].checked){
    format = "12hour";
    if (hours > 12){
    hours -= 12;
    ampm = "P.M";
    }
    else{
    ampm = "A.M";
    }
    }
    else{
    format = "24hour";
    }
    if (seconds < 10){
    seconds = "0" + seconds;
    }
    if (format == "12hour"){
    time = hours+":"+mins+":"+seconds+" "+ampm;
    }
    else{
    time = hours+":"+mins+":"+seconds;
    }
    disp_field.value = time;
    }
    var repeat = window.setInterval("run_clock()",1000);
    </script>
    <div id="display"></div>
    <form>
    <input type="radio" id="format" name="format">format</input>
    <input type="radio" id="format" name="format">format</input>
    </form>
    </body>
    </html>

  5. #5
    Join Date
    Dec 2002
    Location
    St. Louis, MO, USA
    Posts
    1,582
    It's considered bad form to post the same question twice in the same forum; sometimes, even if it's a different category of the same forum.

    ^_^

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles