PDA

View Full Version : Javascript brains required in 'ere please


apt
25-06-2000, 20:32
I know not how to edit Javascript - I just cut 2 separate scripts from a website resource -the problem is I want to put these 2 separate bits on the SAME LINE. The first part simply writes the current date while the second script displays the current time as a clock in a Form.

If you can amalgamate the two so they appear next to one another on the same line I'd be very grateful. I have absolutely no idea how to do it! The "date" script just has a BODY bit, and the "clock" has a HEAD and BODY part. To edit the script you'll need to cut it from the EDIT option just above this message! Many thanks and good luck?!

<BODY>

<SCRIPT LANGUAGE="JavaScript">

<!-- Begin
d = new Array(
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"
);
m = new Array(
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
);

today = new Date();
day = today.getDate();
year = today.getYear();

if (year < 2000) // Y2K Fix, Isaac Powell
year = year + 1900; // http://onyx.idbsu.edu/~ipowell

end = "th";
if (day==1 | | day==21 | | day==31) end="st";
if (day==2 | | day==22) end="nd";
if (day==3 | | day==23) end="rd";
day+=end;

document.write(" ");
document.write(d[today.getDay()]+", "+m[today.getMonth()]+" ");
document.write(day+", " + year);
document.write("</center>");
// End -->
</script>

</BODY>

<!--************************************-->

<HEAD>

<SCRIPT language="JavaScript">
<!--
function startclock()
{
var thetime=new Date();

var nhours=thetime.getHours();
var nmins=thetime.getMinutes();
var nsecn=thetime.getSeconds();
var AorP=" ";

if (nhours>=12)
AorP="pm.";
else
AorP="am.";

if (nhours>=13)
nhours-=12;

if (nhours==0)
nhours=12;

if (nsecn<10)
nsecn="0"+nsecn;

if (nmins<10)
nmins="0"+nmins;

document.clockform.clockspot.value=nhours+": "+nmins+": "+nsecn+" "+AorP;

setTimeout('startclock()',1000);

}
//-->
</SCRIPT>

</HEAD>


<BODY>

<FORM name="clockform">
<INPUT TYPE="text" name="clockspot" size="15">
</FORM>
<SCRIPT language="JavaScript">
<!--
startclock();
//-->
</SCRIPT>

</BODY>

Tech Surfer
26-06-2000, 10:15
How about putting them in separate cells of a table, then they'd be next to each other but also separate, if you know what I mean.

Jinx M
26-06-2000, 11:22
Here you go:

<BLOCKQUOTE><font size="1" face="Verdana">code:</font><HR><pre>
&lt;SCRIPT language="JavaScript"&gt;
&lt;!--
function startclock()
{
var thetime=new Date();
var nhours=thetime.getHours();
var nmins=thetime.getMinutes();
var nsecn=thetime.getSeconds();
var AorP=" ";
if (nhours&gt;=12)
AorP="pm.";
else
AorP="am.";
if (nhours&gt;=13)
nhours-=12;
if (nhours==0)
nhours=12;
if (nsecn&lt;10)
nsecn="0"+nsecn;
if (nmins&lt;10)
nmins="0"+nmins;
document.clockform.clockspot.value=nhours+": "+nmins+": "+nsecn+" "+AorP;
setTimeout('startclock()',1000);
}
//--&gt;
&lt;/SCRIPT&gt;

&lt;/HEAD&gt;
&lt;FORM name="clockform"&gt;

&lt;script language="JavaScript" type="text/javascript"&gt;
&lt;!--
today = new Date();
weekday = today.getDay();
if (weekday == 6) document.write('Saturday');
if (weekday == 0) document.write('Sunday');
if (weekday == 1) document.write('Monday');
if (weekday == 2) document.write('Tuesday');
if (weekday == 3) document.write('Wednesday');
if (weekday == 4) document.write('Thursday');
if (weekday == 5) document.write('Friday');
document.write(' ');
month = today.getMonth();
if (month == 0) document.write('January');
if (month == 1) document.write('Febuary');
if (month == 2) document.write('March');
if (month == 3) document.write('April');
if (month == 4) document.write('May');
if (month == 5) document.write('June');
if (month == 6) document.write('July');
if (month == 7) document.write('August');
if (month == 8) document.write('September');
if (month == 9) document.write('October');
if (month == 10) document.write('November');
if (month == 11) document.write('December');
document.write(' ');
year = today.getYear();
if (year &lt; 2000)
year = year + 1900;
date = today.getDate();
document.write (date ,' ', year);
// --&gt;
&lt;/script&gt;
&lt;INPUT TYPE="text" name="clockspot" size="15"&gt;
&lt;/FORM&gt;
&lt;SCRIPT language="JavaScript"&gt;
&lt;!--
startclock();
//--&gt;
&lt;/SCRIPT&gt;
[/code]

apt
26-06-2000, 22:27
THANKS JINX M!

[This message has been edited by apt (edited 26-06-2000).]