By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,694 Members | 2,122 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,694 IT Pros & Developers. It's quick & easy.

Help with the printdate()

P: n/a
Hello,
I am kind of new to this javascript stuff and I am constantly having
problems trying to get my webpage validated. I have the following
<script>printdate();</script> and when I validate it at validator.w3.org I
get a error the attribute given above is required for an element that you've
used, but you have omitted it. For instance, in most HTML and XHTML document
types the "type" attribute is required on the "script" element and the "alt"
attribute is required for the "img" element.
Typical values for type are type="text/css" for <style> and
type="text/javascript" for <script>.
Ok, I tried both of these obtions but it always change my fonts to some
different then what I want it. How can I have it so my fonts will not
change. If more info is needed please let me know.
thank you for your help to this matter
Jul 23 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
mike wrote:
Hello,
I am kind of new to this javascript stuff and I am constantly having
problems trying to get my webpage validated. I have the following
<script>printdate();</script> and when I validate it at validator.w3.org I
get a error the attribute given above is required for an element that you've
used, but you have omitted it. For instance, in most HTML and XHTML document
types the "type" attribute is required on the "script" element and the "alt"
attribute is required for the "img" element.
Typical values for type are type="text/css" for <style> and
type="text/javascript" for <script>.
Ok, I tried both of these obtions but it always change my fonts to some
different then what I want it. How can I have it so my fonts will not
change. If more info is needed please let me know.
thank you for your help to this matter


<script type="text/javascript"> and <style type="text/css"> should have no
affect on how the fonts appear on your page. Provide a link to two examples that
demonstrate what you are talking about, or two simple examples here. Also note
which browsers you are seeing this behaviour in. If someone can reproduce your
problem, they can help you fix it.

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq

Jul 23 '05 #2

P: n/a
Hello,
Thanks for your reply. I attached part of the script that I am having
problems with which someone might be able to help me out with.
<script language="javascript" type="text/javascript">
<!--
function printdate() {
days = new Array(7)
days[1] = "Sunday";
days[2] = "Monday";
days[3] = "Tuesday";
days[4] = "Wednesday";
days[5] = "Thursday";
days[6] = "Friday";
days[7] = "Saturday";
months = new Array(12)
months[1] = "January";
months[2] = "February";
months[3] = "March";
months[4] = "April";
months[5] = "May";
months[6] = "June";
months[7] = "July";
months[8] = "August";
months[9] = "September";
months[10] = "October";
months[11] = "November";
months[12] = "December";
today = new Date(); day = days[today.getDay() + 1]
month = months[today.getMonth() + 1]
date = today.getDate()
year=today.getYear();
if (year < 2000) year = year + 1900;
document.write ("<font size=1 face='Americana, Arial, Helvetica,
sans-serif' color=003399>" + day +
", " + month + " " + date + ", " + year)
}
More stuff

</script>
<style type="text/css"> <!--
.pviimenudiv td {font-family: "Trebuchet MS", Arial, sans-serif; font-size:
12px}
.pviimenudiv p {font-family: "Trebuchet MS", Arial, sans-serif; font-size:
12px; margin-top: 12px; margin-bottom: 6px}
.pviimenudiv b {font-family: Verdana, Arial, Helvetica, sans-serif;
font-style: normal; color: #666666}
.pviimenudiv a:link {
color: White;
font-family: "Trebuchet MS", Arial, sans-serif;
font-size: 14px;
text-decoration: underline
}
.pviimenudiv a:visited {
color: White;
font-family: "Trebuchet MS", Arial, sans-serif;
font-size: 14px;
text-decoration: underline
}
.pviimenudiv a:hover {
color: Red; font-family: "Trebuchet MS", Arial, sans-serif; font-size:
14px;
text-decoration: underline
}
.pviimenudiv a:active {
color: Red; font-family: "Trebuchet MS", Arial, sans-serif; font-size:
14px;
text-decoration: underline
}
-->
</style>
</head>
<body bgcolor="#FFFFFF" text="#000000"
onLoad="P7_setMenuMagic1(10,40,10,'p7menubottom',' p7menu1','p7submenu1','p7m
but1','p7menu2','p7submenu2','p7mbut2','p7menu3',' p7submenu3','p7mbut3','p7m
enu4','p7submenu4','p7mbut4','p7menu5','p7submenu5 ','p7mbut5');P7_MM1dwt();I
nitAnim();">
<bgsound src="C:\My Documents\test.mids">
<div id="p7menu1" style="position:absolute; left:20px; top:220px;
width:160px; z-index:106"><a href="javascript:;"
onClick="P7_trigMenuMagic1('p7menu1',1);return false"
onMouseOver="P7_rollCMenu1(event,'p7menu1',0)"
onMouseOut="P7_rollCMenu1(event,'p7menu1',0)"
onFocus="if(this.blur)this.blur()"><img src="butt1.gif" width="160"
height="22" name="p7mbut1" border="0" alt="menu 1"></a></div>
<div id="p7menu2" style="position:absolute; left:20px; top:242px;
width:160px; z-index:107"><a href="javascript:;"
onClick="P7_trigMenuMagic1('p7menu2',1);return false"
onMouseOver="P7_rollCMenu1(event,'p7menu2',0)"
onMouseOut="P7_rollCMenu1(event,'p7menu2',0)"
onFocus="if(this.blur)this.blur()"><img src="butt2.gif" width="160"
height="22" name="p7mbut2" border="0" alt="menu 2"></a></div>
<div id="p7submenu1" class="pviimenudiv" style="position:absolute;
left:200px; top:242px; width:150px; visibility: hidden; z-index:101">
<table width="150" border="0" cellspacing="6" cellpadding="0">
<tr>
<td><a href="index.html">Home Page</a></td>
</tr>
</table>
</div>
<div id="p7submenu2" class="pviimenudiv" style="position:absolute;
left:200px; top:264px; width:150px; visibility: hidden; z-index:102">
<table width="150" border="0" cellspacing="6" cellpadding="0">
<tr>
<td><a href="test_pages/test.html">test</a></td>
</tr>
</table>
</div>
<td valign="top">
<table width=468 border=0 align="center" cellpadding=0 cellspacing=0
style="border: 1px;"><tr><td>
<div id="surfer3" style="position:absolute"><img src="test.gif"
alt="test"></div>
<div id="surfer4" style="position:absolute"><img src="test.gif"
alt="test"></div>
<div id="surfer5" style="position:absolute"><img src="test.gif"
alt="test"></div>
<div id="surfer6" style="position:absolute"><img src="test.gif"
alt="test"></div>
<ilayer name="waves34i"><div id="waves34"><img src="test.gif"
alt="test"></div></ilayer>
</td></tr></table>

<br><hr size=1>
<script>printdate();</script>
"Grant Wagner" <gw*****@agricoreunited.com> wrote in message
news:41***************@agricoreunited.com...
mike wrote:
Hello,
I am kind of new to this javascript stuff and I am constantly having
problems trying to get my webpage validated. I have the following
<script>printdate();</script> and when I validate it at validator.w3.org I get a error the attribute given above is required for an element that you've used, but you have omitted it. For instance, in most HTML and XHTML document types the "type" attribute is required on the "script" element and the "alt" attribute is required for the "img" element.
Typical values for type are type="text/css" for <style> and
type="text/javascript" for <script>.
Ok, I tried both of these obtions but it always change my fonts to some
different then what I want it. How can I have it so my fonts will not
change. If more info is needed please let me know.
thank you for your help to this matter
<script type="text/javascript"> and <style type="text/css"> should have no
affect on how the fonts appear on your page. Provide a link to two

examples that demonstrate what you are talking about, or two simple examples here. Also note which browsers you are seeing this behaviour in. If someone can reproduce your problem, they can help you fix it.

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq

Jul 23 '05 #3

P: n/a
JRS: In article <uL*******************@newsread1.news.pas.earthlin k.net
, dated Fri, 13 Aug 2004 01:24:42, seen in news:comp.lang.javascript, mike <nogood@?.invalid> posted :

Read the newsgroup FAQ. Responses should go after trimmed quotes.
Thanks for your reply. I attached part of the script that I am having
problems with which someone might be able to help me out with.
<script language="javascript" type="text/javascript">
<!--
function printdate() {
days = new Array(7)
days[1] = "Sunday";
days[2] = "Monday";
days[3] = "Tuesday";
days[4] = "Wednesday";
days[5] = "Thursday";
days[6] = "Friday";
days[7] = "Saturday";
Space-wasting. days = ["Sunday", ..., "Saturday"]
months = new Array(12)
Likewise
today = new Date(); day = days[today.getDay() + 1]
month = months[today.getMonth() + 1]
date = today.getDate()
year=today.getYear();
if (year < 2000) year = year + 1900;
Does not always work. See FAQ & via sig.
document.write ("<font size=1 face='Americana, Arial, Helvetica,
sans-serif' color=003399>" + day +
", " + month + " " + date + ", " + year)
Forcing font size in that way may be contrary to the spirit of the DDA.
Hash may be needed before 003399.
That date format is not suitable for Internet use; follow ISO 8601.
... "Grant Wagner" <gw*****@agricoreunited.com> wrote in message
news:
... ...


<FAQENTRY>

IMHO, 2.10 should be Multinationalisation. That is adjustment for
different locales, whereas Internationalisation means using a single
form acceptable everywhere. dependant -> dependent.

It would be a good place to recommend, as an example, internationalising
to ISO 8601.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://jibbering.com/faq/> JL / RC : FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #4

P: n/a
> >function printdate() {
days = new Array(7)
days[1] = "Sunday";
days[2] = "Monday";
days[3] = "Tuesday";
days[4] = "Wednesday";
days[5] = "Thursday";
days[6] = "Friday";
days[7] = "Saturday";


Space-wasting. days = ["Sunday", ..., "Saturday"]
months = new Array(12)


These are not the same.

The OP has "Sunday" in array element 1 where you have it in zero.

The statement days = new Array(7) allocates 7 memory locations
starting with
days[0] to days[6]. Your reference to day[7] works fine because
Javascript dynamically allocates memory for the array elements. You
can also declare the array by doing:
days = new Array()

or

days = [ ]

Also, your statement allocated days to the global variable pool. To
have the variable defined to just the function, do

var days = [ ];

Robet
Jul 23 '05 #5

P: n/a
On 13 Aug 2004 21:34:18 -0700, Robert <rc*******@my-deja.com> wrote:
function printdate() {
days = new Array(7)
days[1] = "Sunday";
days[2] = "Monday";
days[3] = "Tuesday";
days[4] = "Wednesday";
days[5] = "Thursday";
days[6] = "Friday";
days[7] = "Saturday";


Space-wasting. days = ["Sunday", ..., "Saturday"]
months = new Array(12)


These are not the same.

The OP has "Sunday" in array element 1 where you have it in zero.


That's because the OP needlessly converts the ordinal from zero- to
one-based. The simple fix to change:

var day = days[today.getDay() + 1];

to

var day = days[today.getDay()];

Shorter. Simpler. Quicker.

Likewise with month. I feel that Dr Stockton should have mentioned it,
though. Perhaps he thought it obvious.

[snip]

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail
Jul 23 '05 #6

P: n/a
Hello,
Thanks for all your great suggestions but can someone try to help me with
the problem of trying to validate this.
"Michael Winter" <M.******@blueyonder.co.invalid> wrote in message
news:opscp1pnt8x13kvk@atlantis...
On 13 Aug 2004 21:34:18 -0700, Robert <rc*******@my-deja.com> wrote:
function printdate() {
days = new Array(7)
days[1] = "Sunday";
days[2] = "Monday";
days[3] = "Tuesday";
days[4] = "Wednesday";
days[5] = "Thursday";
days[6] = "Friday";
days[7] = "Saturday";

Space-wasting. days = ["Sunday", ..., "Saturday"]

months = new Array(12)


These are not the same.

The OP has "Sunday" in array element 1 where you have it in zero.


That's because the OP needlessly converts the ordinal from zero- to
one-based. The simple fix to change:

var day = days[today.getDay() + 1];

to

var day = days[today.getDay()];

Shorter. Simpler. Quicker.

Likewise with month. I feel that Dr Stockton should have mentioned it,
though. Perhaps he thought it obvious.

[snip]

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail

Jul 23 '05 #7

P: n/a
"mike" <nogood@.invalid> wrote in message news:<RT***************@newsread2.news.pas.earthli nk.net>...
Hello,
Thanks for all your great suggestions but can someone try to help me with
the problem of trying to validate this.


I have not seen the output from the validator, but the text field is
required in the script tag. Try:

<SCRIPT type="text/javascript">
printdate();
</script>
You provided a rather large code fragment. We cannot copy and paste
it into a file and run it to see what any problems are. Please
provide a link or a working example. The code fragement you provide
is rather large and complex. It includes about everything but the
kitchen sink: styles, div, table, and iframe.

We may have gotten distracted my the complexity of the fragment. You
original post was about some error messages from the W3C verifier.
Could you provide details about what version of the verifier you are
using, the error messages you got, and an exact copy of the file you
used. Could you trim down the file to a small size and give the error
message you see.

This is a JavaScript forum. You have gotten some great people to
respond to your post.

Robert
Jul 23 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.