i am using a train schedule script that genartes train schdule based upon the array value,
what i am trying to do is to set those array values from my text box, how can i do it? thx in advance.really appreciate the help.
<HEAD>
<script>
<!-- Begin
/*
stationname: array of station names in sequence with 1st station
timediff: array of times from 1st station
starting: array of departure times from 1st station
*/
var nameStation = new Array("Startville", "Twoshire ", "Threeham ", "Fourhampton",
"Terminus ");
var timeDiff = new Array("0:00", "1:03", "1:18", "1:43", "0:153"); // time to last
station is 2 hours and 33 minutes = 153 minutes
var timeStart = new Array("12:00", "1:30", "3:05");
// initalize
var lines = new Array
nl = "\n";
t1 = "\t";
t2 = "\t\t";
i = 0;
function print2doc(){
// head the schedule
lines[0] = nameStation[i] +t1+ nameStation[++i] +t1+ nameStation[++i] +t1+
nameStation[++i] +t1+ nameStation[++i]+nl
//v = sumTime(timeStart[1],timeDiff[4]); alert(v); return // this for
testing
// build the lines for printing
for (i=0; i<3; i++) {
lines[i+1] = timeStart[i] +t2+ sumTime(timeStart[i],timeDiff[1]) +t2+
sumTime(timeStart,timeDiff[2]) +t2+ sumTime(timeStart,timeDiff[3]) +t2+ sumTime
(timeStart,timeDiff[4]) + nl;
}
text = '<b><i>'+lines[0]+'</i></b>' + lines[1] +lines[2] + lines[3]
//alert(text)
// make a window for train schedule
nw = window.open("","popWin","width=600,height=200")
// write to window
nw.document.open();
nw.document.write("<html>\n<body bgcolor='lightsteelblue'>\n<h2
align='center'>Train Schedule</h2>\n<pre>\n");
nw.document.write(text);
nw.document.write("</pre>\n</body>\n</html>");
nw.document.close();
}
function sumTime(startT,deltaT){ // add times
time1 = startT.split(":");
time2 = deltaT.split(":");
hours = time1[0]/1 + time2[0]/1; // add hours
minutes = time1[1]/1 + time2[1]/1; // add minutes
if (minutes >=180) { hours++; minutes = minutes - 60; } // bump hours if
needed
if (minutes >=120) { hours++; minutes = minutes - 60; } // bump hours if
needed
if (minutes >= 60) { hours++; minutes = minutes % 60; } // bump again if
needed
if (minutes < 10) minutes = "0" + minutes;
// add padding if required
time3 = hours +":"+ minutes
//alert(time3)
return time3 // return the total as a string
}
// End -->
</script>
</HEAD>
<!-- STEP TWO: Insert the onLoad event handler into your BODY tag -->
<BODY onUnload="if (!nw.closed) nw.close()">
<!-- STEP THREE: Copy this code into the BODY of your HTML document -->
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Original: Rick Johnson (frj11@yahoo.com ) -->
<!-- Web Site: http://208.255.209.164/myPage/ -->
<form>
<input type=button value="Generate the Schedule" onClick="print2doc()"
style="background-color: gold;">
</form>
</div>
<!-- Script Size: 3.46 KB -->