javascript alert message problem

mattura

Member
Messages
570
Reaction score
2
Points
18
Hmm, I can't access the web site...

perhaps if you post the code...
 

VPmase

New Member
Messages
914
Reaction score
0
Points
0
Move the javascript code below the <body> tag.

Like so:

HTML:
<body onload="message();">
<script type="text/javascript">
function message()
{
alert("currently working on another website and learning javascript");
}
</script>
....
 

Otaku Ichise

New Member
Messages
64
Reaction score
0
Points
0
Move the javascript code below the <body> tag.

Like so:

HTML:
<body onload="message();">
<script type="text/javascript">
function message()
{
alert("currently working on another website and learning javascript");
}
</script>
....

still doesnt work.
 

daman371

New Member
Messages
130
Reaction score
0
Points
0
Code:
<script type="text/javascript">
function message()
{
alert("currently working on another website and learning javascript");
}
</script>
<body onLoad="javascript:message();">

Also acceptable:

Code:
<script type="text/javascript">
function message()
{
alert("currently working on another website and learning javascript");
}
</script>
<body onLoad="message();">
 
Last edited:

VPmase

New Member
Messages
914
Reaction score
0
Points
0
still doesnt work.
I went through your code and noticed that time.js doesn't exist even though you call it in your page.

<script src="index_files/time.js"></script>

That line was what makes it not run right.
 

mattura

Member
Messages
570
Reaction score
2
Points
18
Yep, try removing all other javascripts first, then when you add them, if they break it, you know where the problem is!
If the following code is on your page, without any other script, it will work:
Code:
<head>
...
<script type="text/javascript">
function message() {
 alert("Welcome");
}
</script>
</head>
<body onLoad="message();">
...
 

Otaku Ichise

New Member
Messages
64
Reaction score
0
Points
0
I mentioned above the script alert message works only if i take those 2 other .js scripts, somehow they cancel the alert message and the code inside .js files is this:

Date.js
//<![CDATA[
/*Current date script credit:
JavaScript Kit (www.javascriptkit.com)
*/
var mydate=new Date()
var year=mydate.getYear()
if (year < 1000)
year+=1900
var day=mydate.getDay()
var month=mydate.getMonth()
var daym=mydate.getDate()
if (daym<10)
daym="0"+daym
var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
var montharray=new Array("January","February","March","April","May","June","July","August","September","October","November","December")
document.write("<font color='#BBD6EC' face='Palatino Linotype'><b>"+dayarray[day]+", "+montharray[month]+" "+daym+", "+year+"</b></font>")
//]]>

time.js
//<![CDATA[
/*By JavaScript Kit
http://javascriptkit.com
Credit MUST stay intact for use
*/
function show2(){
if (!document.all&&!document.getElementById)
return
thelement=document.getElementById? document.getElementById("tick2"): document.all.tick2
var Digital=new Date()
var hours=Digital.getHours()
var minutes=Digital.getMinutes()
var seconds=Digital.getSeconds()
var dn="PM"
if (hours<12)
dn="AM"
if (hours>12)
hours=hours-12
if (hours==0)
hours=12
if (minutes<=9)
minutes="0"+minutes
if (seconds<=9)
seconds="0"+seconds
var ctime=hours+":"+minutes+":"+seconds+" "+dn
thelement.innerHTML="<b style='color:#BBD6EC; font-family:times new roman'>"+ctime+"</b>"
setTimeout("show2()",1000)
}
window.onload=show2
//]]>
 
Last edited:

VPmase

New Member
Messages
914
Reaction score
0
Points
0
Use this for your time.js

Code:
//<![CDATA[
/*By JavaScript Kit
http://javascriptkit.com
Credit MUST stay intact for use
*/
function show2(){
if (!document.all&&!document.getElementById){
return;}
thelement=document.getElementById? document.getElementById("tick2"): document.all.tick2;
var Digital=new Date();
var hours=Digital.getHours();
var minutes=Digital.getMinutes();
var seconds=Digital.getSeconds();
var dn="PM";
if (hours<12){
dn="AM";}
if (hours>12){
hours=hours-12;}
if (hours==0){
hours=12;}
if (minutes<=9){
minutes="0"+minutes;}
if (seconds<=9){
seconds="0"+seconds;}
var ctime=hours+":"+minutes+":"+seconds+" "+dn;
thelement.innerHTML="<b style='color:#BBD6EC; font-family:times new roman'>"+ctime+"</b>";
setTimeout(show2(),1000);
}
window.onload=show2();
//]]>
I cleaned up your script. You should really use semicolons (;)...
 

mattura

Member
Messages
570
Reaction score
2
Points
18
Yep those scripts were the problem.

I'd suggest replacing the Date script with the following (much shorter) php:
PHP:
<?php
$dat=date("D jS F Y");
echo "<font color='#BBD6EC' face='Palatino Linotype'><b>$dat</b></font>";
?>
look up the date() function for additional information
 
Last edited:
Top