Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Nov 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    creating & displaying a timetable using javascript

    Hi guys!!! Hope you all cool!!
    i was just browsing around for possible solutions and came on this place and thought might as well try here.
    Hope you folk can be kind enough to spare a few minutes for our problem????

    Heres the info i have been given:

    var stationNames = new Array ()
    stationNames[0] = "station1"
    stationNames[1] = "station2"
    stationNames[2] = "station3"
    stationNames[3] = "station4"
    stationNames[4] = "station5"

    var intervals = new Array ()
    intervals [0] = "10"
    intervals [1] = "9"
    intervals [2] = "3"
    intervals [3] = "5"

    var startTimes = new Array ()
    startTimes[0] = "15:40"
    startTimes[1] = "16:50"
    startTimes[2] = "17:59"
    startTimes[3] = "18:10"
    startTimes[4] = "23:48"
    startTimes[5] = "0:01"

    basically what i want to do is to create a time table that displays the the times that the train will arrive at the stations using the startTimes and intervals to work it out.
    easy.
    couple of my friends and I put our heads together and managed to figure it out and I put the code below as well.
    the problem we are having at the moment is to display the info in a table format.
    i mean, do i like create a table in html and then in each cell put in a reference to the calculations done by the javascript??? how?? i dont get it??

    and feedback would be greatly appreciated!!

    o, and also if some one can improve on our existing code, then the better!!!!

    <script language="JavaScript">

    function mod(m,n)
    {
    return (m,0 ? mod(m+n,n) : m % n);
    }

    function div(m,n)
    {
    return (m - mod(m,n))/n ;
    }

    function timetoString()
    {
    return this.hour + ":" + this.mins;
    }


    function timeFromString(s)
    {
    var list = s.split(':');
    var h = parseInt(list[0], 10);
    var m = parseInt(list[1],10);
    this.hour = mod(h+ div(m,60),24); this.mins = mod(m,60);
    }

    function timeAddMin(n)
    {
    this.hour = mod(this.hour + div(this.mins+n,60), 24);
    this.mins = mod(this.mins+n, 60);
    }

    function timeAddMinString(s)
    {
    this.addMin(parseInt(s, 10));
    }


    function Time (h,m)
    {
    this.hour = mod(h + div(m,60), 24);
    this.mins = mod(m, 60);
    this.toString = timetoString;
    this.fromString = timeFromString;
    this.addMin = timeAddMin;
    this.addMinString = timeAddMinString;
    }

    function calcExample(t,m)
    {
    var temp = new Time(0,0);
    temp.fromString(t);
    temp.addMinString(m);
    return temp.toString();
    }

    function DocodeForCalcExample(infield1,infield2)
    {
    var outfield;
    outfield = calcExample(infield1, infield2);
    return outfield;
    }

    </script>

  • #2
    New to the CF scene
    Join Date
    Nov 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    no help??

    so no one then??

  • #3
    Banned
    Join Date
    Oct 2005
    Location
    I'm in GMT -5
    Posts
    314
    Thanks
    0
    Thanked 1 Time in 1 Post
    vittel:
    An example, nothing more...
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Bus Schedule</title>
    <script type="text/javascript">
    
    	timetable = ["1000", "1130", "1330", "1530", "1730", "2030", "1145", "1315", "1515", "1730", "1930", "2205", "1210", "1340", "1540", "1800", "1950", "2230", "1330", "1500", "1700", "1915", "2100", "2345", "1435", "1600", "1810", "2030", "2220", "0100"];
    	cities = ["Dublin", "Castlecomer", "Kilkenny", "Clonmel", "Fermoy"];
    	var isTable = "";
    	var nRows = "";
    	var nCells = "";
    		
    	function dispSched(){
    
    		for (i=1; i<nRows+1; i++)
    			{isTable.rows[i].cells[0].lastChild.data = cities[i-1]}
    		for (i=0; i<nRows; i++)
    			{
    			 for (n=0; n<nCells; n++)
    				{
    			 	 isTable.rows[i+1].cells[n+1].lastChild.data = timetable[n+(i*nCells)];
    				}
    			}		
    	}
    
    	function mapTable(){
    
    		isTable = document.getElementById('dublinFermoy');
    		nRows = isTable.rows.length-1;
    		nCells = isTable.rows[0].cells.length-1;
    		dispSched();
    	}
    
    	onload=mapTable;		
    
    </script>
    </head>
        <body>
          <h4>
             GoByBus Dublin - Fermoy Timetable
          </h4><br>
    
          <table id='dublinFermoy' width="400" border='1' cellspacing='5' cellpadding='5'>
             <tbody>
                <tr>
                   <td></td>
                   <td>
                      depart
                   </td>
                   <td>
                      depart
                   </td>
                   <td>
                      depart
                   </td>
                   <td>
                      depart
                   </td>
                   <td>
                      depart
                   </td>
                   <td>
                      depart
                   </td>
                </tr>
                <tr>
                   <td>
                      &nbsp;
                   </td>
                   <td>
                      &nbsp;
                   </td>
                   <td>
                      &nbsp;
                   </td>
                   <td>
                      &nbsp;
                   </td>
                   <td>
                      &nbsp;
                   </td>
                   <td>
                      &nbsp;
                   </td>
                   <td>
                      &nbsp;
                   </td>
                </tr>
                <tr>
                   <td>
                      &nbsp;
                   </td>
                   <td>
                      &nbsp;
                   </td>
                   <td>
                      &nbsp;
                   </td>
                   <td>
                      &nbsp;
                   </td>
                   <td>
                      &nbsp;
                   </td>
                   <td>
                      &nbsp;
                   </td>
                   <td>
                      &nbsp;
                   </td>
                </tr>
                <tr>
                   <td>
                      &nbsp;
                   </td>
                   <td>
                      &nbsp;
                   </td>
                   <td>
                      &nbsp;
                   </td>
                   <td>
                      &nbsp;
                   </td>
                   <td>
                      &nbsp;
                   </td>
                   <td>
                      &nbsp;
                   </td>
                   <td>
                      &nbsp;
                   </td>
                </tr>
                <tr>
                   <td>
                      &nbsp;
                   </td>
                   <td>
                      &nbsp;
                   </td>
                   <td>
                      &nbsp;
                   </td>
                   <td>
                      &nbsp;
                   </td>
                   <td>
                      &nbsp;
                   </td>
                   <td>
                      &nbsp;
                   </td>
                   <td>
                      &nbsp;
                   </td>
                </tr>
                <tr>
                   <td>
                      &nbsp;
                   </td>
                   <td>
                      &nbsp;
                   </td>
                   <td>
                      &nbsp;
                   </td>
                   <td>
                      &nbsp;
                   </td>
                   <td>
                      &nbsp;
                   </td>
                   <td>
                      &nbsp;
                   </td>
                   <td>
                      &nbsp;
                   </td>
                </tr>
             </tbody>
          </table>
       </body>
    </html>


  •  

    Posting Permissions

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