Help with the printdate()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mike

    Help with the printdate()

    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>printda te();</script> and when I validate it at validator.w3.or g 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


  • Grant Wagner

    #2
    Re: Help with the printdate()

    mike wrote:
    [color=blue]
    > 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>printda te();</script> and when I validate it at validator.w3.or g 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[/color]

    <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 <gwagner@agrico reunited.com>
    comp.lang.javas cript FAQ - http://jibbering.com/faq

    Comment

    • mike

      #3
      Re: Help with the printdate()

      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="javas cript" 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.getY ear();
      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="#FFFFF F" text="#000000"
      onLoad="P7_setM enuMagic1(10,40 ,10,'p7menubott om','p7menu1',' p7submenu1','p7 m
      but1','p7menu2' ,'p7submenu2',' p7mbut2','p7men u3','p7submenu3 ','p7mbut3','p7 m
      enu4','p7submen u4','p7mbut4',' p7menu5','p7sub menu5','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="javascrip t:;"
      onClick="P7_tri gMenuMagic1('p7 menu1',1);retur n false"
      onMouseOver="P7 _rollCMenu1(eve nt,'p7menu1',0) "
      onMouseOut="P7_ rollCMenu1(even t,'p7menu1',0)"
      onFocus="if(thi s.blur)this.blu r()"><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="javascrip t:;"
      onClick="P7_tri gMenuMagic1('p7 menu2',1);retur n false"
      onMouseOver="P7 _rollCMenu1(eve nt,'p7menu2',0) "
      onMouseOut="P7_ rollCMenu1(even t,'p7menu2',0)"
      onFocus="if(thi s.blur)this.blu r()"><img src="butt2.gif" width="160"
      height="22" name="p7mbut2" border="0" alt="menu 2"></a></div>
      <div id="p7submenu1 " class="pviimenu div" 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.htm l">Home Page</a></td>
      </tr>
      </table>
      </div>
      <div id="p7submenu2 " class="pviimenu div" 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_page s/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"><i mg src="test.gif"
      alt="test"></div></ilayer>
      </td></tr></table>

      <br><hr size=1>
      <script>printda te();</script>


      "Grant Wagner" <gwagner@agrico reunited.com> wrote in message
      news:411B831E.8 6EEA8E6@agricor eunited.com...[color=blue]
      > mike wrote:
      >[color=green]
      > > 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>printda te();</script> and when I validate it at validator.w3.or g[/color][/color]
      I[color=blue][color=green]
      > > get a error the attribute given above is required for an element that[/color][/color]
      you've[color=blue][color=green]
      > > used, but you have omitted it. For instance, in most HTML and XHTML[/color][/color]
      document[color=blue][color=green]
      > > types the "type" attribute is required on the "script" element and the[/color][/color]
      "alt"[color=blue][color=green]
      > > 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[/color]
      >
      > <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[/color]
      examples that[color=blue]
      > demonstrate what you are talking about, or two simple examples here. Also[/color]
      note[color=blue]
      > which browsers you are seeing this behaviour in. If someone can reproduce[/color]
      your[color=blue]
      > problem, they can help you fix it.
      >
      > --
      > Grant Wagner <gwagner@agrico reunited.com>
      > comp.lang.javas cript FAQ - http://jibbering.com/faq
      >[/color]


      Comment

      • Dr John Stockton

        #4
        Re: Help with the printdate()

        JRS: In article <uLUSc.19211$9Y 6.13066@newsrea d1.news.pas.ear thlink.net[color=blue]
        >, dated Fri, 13 Aug 2004 01:24:42, seen in news:comp.lang. javascript,[/color]
        mike <nogood@?.inval id> posted :

        Read the newsgroup FAQ. Responses should go after trimmed quotes.
        [color=blue]
        >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="javas cript" 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";[/color]

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

        Likewise
        [color=blue]
        > today = new Date(); day = days[today.getDay() + 1]
        > month = months[today.getMonth( ) + 1]
        > date = today.getDate()
        > year=today.getY ear();
        > if (year < 2000) year = year + 1900;[/color]

        Does not always work. See FAQ & via sig.
        [color=blue]
        > document.write ("<font size=1 face='Americana , Arial, Helvetica,
        >sans-serif' color=003399>" + day +
        > ", " + month + " " + date + ", " + year)[/color]

        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.
        [color=blue]
        > ...[/color]
        [color=blue]
        >"Grant Wagner" <gwagner@agrico reunited.com> wrote in message
        >news:
        > ... ...[/color]

        <FAQENTRY>

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

        It would be a good place to recommend, as an example, internationalis ing
        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.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
        <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

        Comment

        • Robert

          #5
          Re: Help with the printdate()

          > >function printdate() {[color=blue][color=green]
          > >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";[/color]
          >
          > Space-wasting. days = ["Sunday", ..., "Saturday"]
          >[color=green]
          > > months = new Array(12)[/color][/color]

          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

          Comment

          • Michael Winter

            #6
            Re: Help with the printdate()

            On 13 Aug 2004 21:34:18 -0700, Robert <rccharles@my-deja.com> wrote:
            [color=blue][color=green][color=darkred]
            >>> 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";[/color]
            >>
            >> Space-wasting. days = ["Sunday", ..., "Saturday"]
            >>[color=darkred]
            >>> months = new Array(12)[/color][/color]
            >
            > These are not the same.
            >
            > The OP has "Sunday" in array element 1 where you have it in zero.[/color]

            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

            Comment

            • mike

              #7
              Re: Help with the printdate()

              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.Winter@bluey onder.co.invali d> wrote in message
              news:opscp1pnt8 x13kvk@atlantis ...[color=blue]
              > On 13 Aug 2004 21:34:18 -0700, Robert <rccharles@my-deja.com> wrote:
              >[color=green][color=darkred]
              > >>> 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)[/color]
              > >
              > > These are not the same.
              > >
              > > The OP has "Sunday" in array element 1 where you have it in zero.[/color]
              >
              > 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[/color]


              Comment

              • Robert

                #8
                Re: Help with the printdate()

                "mike" <nogood@.invali d> wrote in message news:<RTvTc.208 $3O3.187@newsre ad2.news.pas.ea rthlink.net>...[color=blue]
                > Hello,
                > Thanks for all your great suggestions but can someone try to help me with
                > the problem of trying to validate this.[/color]

                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

                Comment

                Working...