SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jan 2007
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Transform infos from a box into text

    Hello,

    On this page, I'm using a JS displaying time in 2 cities. As you can see, time is displayed within a box.

    I would like to know if I can display time as a text.

    Someone told me to use the following code:
    Code:
    var element = document.getElementById(MY_ID_STR); 
    element.innerHTML = GetMyResult();
    But I don't know where to put it.

    Thanks for your help.

  2. #2
    SitePoint Zealot
    Join Date
    Jul 2006
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You are currently adding your script to the text inputs using the following two lines:

    Original:
    Code:
    // 1st line:
    document.formhorloge_Paris.horloge.value = heures + minutes + secondes;
    
    // 2nd line:
    document.formhorloge_Chicago.horloge.value = heures2 + minutes2 + secondes2;
    Replacements:
    Code:
    var element = document.getElementById(MY_ID_STR); 
    element.innerHTML = heures + minutes + secondes;
    So you want to replace the two lines way above each with the 2 lines just above where MY_ID_STR = "the_id_of_the_text_div_you_want_to_put_your_clock", which means you will end up replacing 2 lines with 4 lines.

  3. #3
    SitePoint Zealot
    Join Date
    Jul 2006
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <head>
    <script language="JavaScript">
    <!--
    //PLF-http://www.jejavascript.net/
    //modified by GouZi http://gouziatiit.free.fr
    function heure() {
    //Horloge a l'heure de Paris
    var dd;
    var Maintenant = new Date();
    var fuseau = Maintenant.getTimezoneOffset();
    var heures = Maintenant.getHours();
    var minutes = Maintenant.getMinutes();
    var secondes = Maintenant.getSeconds();
    //Dcalage par rapport  Greenwich (GMT) - +1 pour Paris
    heures = heures + (fuseau/60)+1;
    //heure t
    var annee = Maintenant.getFullYear();
    for (i=31; i >24; i--) {
    dimanche = new Date(annee, 2, i);
    if (dimanche.getDay()==0) break;
    }
    for (i=31; i >24; i--) {
    dimanche2 = new Date(annee, 9, i);
    if (dimanche2.getDay()==0) break;
    }
    if (Maintenant >= dimanche && Maintenant < dimanche2) heures = heures + 1;
    //heure t
    // quelques corrections pour retablir des heures inferieures a 0H et superieures a 23H
    if ( heures < 0 ) {
    heures = 24 + heures;
    }
    if (heures > 23) {
    heures = heures - 24;
    }
    heures = ((heures < 10) ? " 0" : " ") + heures;
    minutes = ((minutes < 10) ? ":0" : ":") + minutes;
    secondes = ((secondes < 10) ? ":0" : ":") + secondes;
    // formhorloge_Paris: nom du formulaire pour l'horloge a l'heure de Paris
    // horloge: nom de l'input, o sera affich l'horloge
    document.getElementById("paris").innerHTML = heures + minutes + secondes;
    
    //Horloge de San Diego
    //de meme sauf qu'on a pas besoin de l'heure d't
    var Maintenant2 = new Date();
    var fuseau2 = Maintenant2.getTimezoneOffset();
    var heures2 = Maintenant2.getHours();
    var minutes2 = Maintenant2.getMinutes();
    var secondes2 = Maintenant2.getSeconds();
    //Dcalage par rapport  Greenwich (GMT) -9 pour San Diego
    heures2 = heures2 + (fuseau2/60)-8;
    // quelques corrections pour retablir des heures inferieures a 0H et superieures a 23H
    if ( heures2 < 0 ) {
    heures2 = 24 + heures2;
    }
    if (heures2 > 23) {
    heures2 = heures2 - 24;
    }
    heures2 = ((heures2 < 10) ? " 0" : " ") + heures2;
    minutes2 = ((minutes2 < 10) ? ":0" : ":") + minutes2;
    secondes2 = ((secondes2 < 10) ? ":0" : ":") + secondes2;
    document.getElementById("sandiego").innerHTML = heures2 + minutes2 + secondes2;
    dd=setTimeout("heure()",1000);
    }
    //-->
    </script>
    </head>
    
    <body onload="heure()" >
    
    <table> 
    <tr>
    <td width="50&#37;"><p>Paris</p></td>
    <td width="50%"><div id="paris"></div></td>
    </tr>
    </table>
    
    <table>
    <tr>
    <td width="50%"><p>San Diego</p></td>
    <td width="50%"><div id="sandiego"></div></td>
    </tr>
    </table>
    
    </body>
    </html>

  4. #4
    SitePoint Member
    Join Date
    Jan 2007
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It works fine, thank you very much indeed.


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
  •