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

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.
LVL 1
steve_mick972Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

archrajanCommented:
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
archrajanCommented:
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
archrajanCommented:
u can remove the alert statement
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.