[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Javascript Variable set. How to display it in my TD element.

Posted on 2004-11-30
3
Medium Priority
?
223 Views
Last Modified: 2012-06-21
I have the following javascript function in my HTML page.


                  <script language="JavaScript">
            
            function dateFormat(aDate, displayPat){
                  /********************************************************
                  *   Valid Masks:
                  *   !mmmm = Long month (eg. January)
                  *   !mmm = Short month (eg. Jan)
                  *   !mm = Numeric date (eg. 07)
                  *   !m = Numeric date (eg. 7)
                  *   !dddd = Long day (eg. Monday)
                  *   !ddd = Short day (eg. Mon)
                  *   !dd = Numeric day (eg. 07)
                  *   !d = Numeric day (eg. 7)
                  *   !yyyy = Year (eg. 1999)
                  *   !yy = Year (eg. 99)
            ********************************************************/

                  intMonth = aDate.getMonth();
                  intDate = aDate.getDate();
                  intDay = aDate.getDay();
                  intYear = aDate.getFullYear();

                  var months_long =  new Array ('January','February','March','April',
                  'May','June','July','August','September','October','November','December')
                  var months_short = new Array('Jan','Feb','Mar','Apr','May','Jun',
                  'Jul','Aug','Sep','Oct','Nov','Dec')
                  var days_long = new Array('Sunday','Monday','Tuesday','Wednesday',
                  'Thursday','Friday','Saturday')
                  var days_short = new Array('Sun','Mon','Tue','Wed','Thu','Fri','Sat')

                  var mmmm = months_long[intMonth]
                  var mmm = months_short[intMonth]
                  var mm = intMonth < 9?'0'+ (1 + intMonth) + '':(1+intMonth)+'';
                  var m = 1+intMonth+'';
                  var dddd = days_long[intDay];
                  var ddd = days_short[intDay];
                  var dd = intDate<10?'0'+intDate+'':intDate+'';
                  var d = intDate+'';
                  var yyyy = intYear;

                  century = 0;
                  while((intYear-century)>=100)
                        century = century + 100;

                  var yy = intYear - century
                  if(yy<10)
                        yy = '0' + yy + '';

                  displayDate = new String(displayPat);

                  displayDate = displayDate.replace(/!mmmm/i,mmmm);
                  displayDate = displayDate.replace(/!mmm/i,mmm);
                  displayDate = displayDate.replace(/!mm/i,mm);
                  displayDate = displayDate.replace(/!m/i,m);
                  displayDate = displayDate.replace(/!dddd/i,dddd);
                  displayDate = displayDate.replace(/!ddd/i,ddd);
                  displayDate = displayDate.replace(/!dd/i,dd);
                  displayDate = displayDate.replace(/!d/i,d);
                  displayDate = displayDate.replace(/!yyyy/i,yyyy);
                  displayDate = displayDate.replace(/!yy/i,yy);

                  return displayDate;
            }
            
            var dateString = dateFormat(new Date() , '!dddd,  !mmmm !dd,  !yyyy');            
      </script>


Now i Have a TD element within my HTML body, where i want to set the contents of this to


 <td>dateString</td>



Here i want to be able to print the value of the javascript variable dateString.


Thanks in advance.

It only a html page.
0
Comment
Question by:steve_mick972
  • 3
3 Comments
 
LVL 25

Expert Comment

by:archrajan
ID: 12710433
script language="JavaScript">
         
          function dateFormat(aDate, displayPat){
               /********************************************************
               *   Valid Masks:
               *   !mmmm = Long month (eg. January)
               *   !mmm = Short month (eg. Jan)
               *   !mm = Numeric date (eg. 07)
               *   !m = Numeric date (eg. 7)
               *   !dddd = Long day (eg. Monday)
               *   !ddd = Short day (eg. Mon)
               *   !dd = Numeric day (eg. 07)
               *   !d = Numeric day (eg. 7)
               *   !yyyy = Year (eg. 1999)
               *   !yy = Year (eg. 99)
          ********************************************************/

               intMonth = aDate.getMonth();
               intDate = aDate.getDate();
               intDay = aDate.getDay();
               intYear = aDate.getFullYear();

               var months_long =  new Array ('January','February','March','April',
               'May','June','July','August','September','October','November','December')
               var months_short = new Array('Jan','Feb','Mar','Apr','May','Jun',
               'Jul','Aug','Sep','Oct','Nov','Dec')
               var days_long = new Array('Sunday','Monday','Tuesday','Wednesday',
               'Thursday','Friday','Saturday')
               var days_short = new Array('Sun','Mon','Tue','Wed','Thu','Fri','Sat')

               var mmmm = months_long[intMonth]
               var mmm = months_short[intMonth]
               var mm = intMonth < 9?'0'+ (1 + intMonth) + '':(1+intMonth)+'';
               var m = 1+intMonth+'';
               var dddd = days_long[intDay];
               var ddd = days_short[intDay];
               var dd = intDate<10?'0'+intDate+'':intDate+'';
               var d = intDate+'';
               var yyyy = intYear;

               century = 0;
               while((intYear-century)>=100)
                    century = century + 100;

               var yy = intYear - century
               if(yy<10)
                    yy = '0' + yy + '';

               displayDate = new String(displayPat);

               displayDate = displayDate.replace(/!mmmm/i,mmmm);
               displayDate = displayDate.replace(/!mmm/i,mmm);
               displayDate = displayDate.replace(/!mm/i,mm);
               displayDate = displayDate.replace(/!m/i,m);
               displayDate = displayDate.replace(/!dddd/i,dddd);
               displayDate = displayDate.replace(/!ddd/i,ddd);
               displayDate = displayDate.replace(/!dd/i,dd);
               displayDate = displayDate.replace(/!d/i,d);
               displayDate = displayDate.replace(/!yyyy/i,yyyy);
               displayDate = displayDate.replace(/!yy/i,yy);

               return displayDate;
          }
         
          var dateString = dateFormat(new Date() , '!dddd,  !mmmm !dd,  !yyyy');
              document.getElementById('here').innerHTML = dateString;
     </script>


Now i Have a TD element within my HTML body, where i want to set the contents of this to


 <td id = "here">dateString</td>






0
 
LVL 25

Expert Comment

by:archrajan
ID: 12710460
sorry see this working example
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<script language="JavaScript">
         
          function dateFormat(aDate, displayPat){
               /********************************************************
               *   Valid Masks:
               *   !mmmm = Long month (eg. January)
               *   !mmm = Short month (eg. Jan)
               *   !mm = Numeric date (eg. 07)
               *   !m = Numeric date (eg. 7)
               *   !dddd = Long day (eg. Monday)
               *   !ddd = Short day (eg. Mon)
               *   !dd = Numeric day (eg. 07)
               *   !d = Numeric day (eg. 7)
               *   !yyyy = Year (eg. 1999)
               *   !yy = Year (eg. 99)
          ********************************************************/

               intMonth = aDate.getMonth();
               intDate = aDate.getDate();
               intDay = aDate.getDay();
               intYear = aDate.getFullYear();

               var months_long =  new Array ('January','February','March','April',
               'May','June','July','August','September','October','November','December')
               var months_short = new Array('Jan','Feb','Mar','Apr','May','Jun',
               'Jul','Aug','Sep','Oct','Nov','Dec')
               var days_long = new Array('Sunday','Monday','Tuesday','Wednesday',
               'Thursday','Friday','Saturday')
               var days_short = new Array('Sun','Mon','Tue','Wed','Thu','Fri','Sat')

               var mmmm = months_long[intMonth]
               var mmm = months_short[intMonth]
               var mm = intMonth < 9?'0'+ (1 + intMonth) + '':(1+intMonth)+'';
               var m = 1+intMonth+'';
               var dddd = days_long[intDay];
               var ddd = days_short[intDay];
               var dd = intDate<10?'0'+intDate+'':intDate+'';
               var d = intDate+'';
               var yyyy = intYear;

               century = 0;
               while((intYear-century)>=100)
                    century = century + 100;

               var yy = intYear - century
               if(yy<10)
                    yy = '0' + yy + '';

               displayDate = new String(displayPat);

               displayDate = displayDate.replace(/!mmmm/i,mmmm);
               displayDate = displayDate.replace(/!mmm/i,mmm);
               displayDate = displayDate.replace(/!mm/i,mm);
               displayDate = displayDate.replace(/!m/i,m);
               displayDate = displayDate.replace(/!dddd/i,dddd);
               displayDate = displayDate.replace(/!ddd/i,ddd);
               displayDate = displayDate.replace(/!dd/i,dd);
               displayDate = displayDate.replace(/!d/i,d);
               displayDate = displayDate.replace(/!yyyy/i,yyyy);
               displayDate = displayDate.replace(/!yy/i,yy);

               return displayDate;
          }
         
          var dateString = dateFormat(new Date() , '!dddd,  !mmmm !dd,  !yyyy');
              alert(dateString);
     </script>













</HEAD>

<BODY>
 <td><script>document.write(dateString)</script></td>

</BODY>
</HTML>
0
 
LVL 25

Accepted Solution

by:
archrajan earned 2000 total points
ID: 12710462
u can remove the alert statement
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question