HTML Tutorial


 Forum HomeForum Home   FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
RegisterRegister - Not registered yet? Got something to say? Join HTML Code Tutorial!
Button code to display the date and time in another cell
Post new topic   Reply to topic    HTML Help Forum Index -> HTML Form
View previous topic :: View next topic  
Author Message
ejs7a



Joined: 06 Jun 2005
Posts: 4

PostPosted: Mon Jun 06, 2005 10:27 am     Button code to display the date and time in another cell Reply with quote

Here is my question:
I want to create a table that has two columns one column will have a push button that says Update and when you push that button, it will populate the next column with the current date and time. I can create the table the basic button, but am having problems getting the button to put the current date in the next column over. Help?
degsy



Joined: 23 Feb 2005
Posts: 2440
Location: North East, UK

PostPosted: Mon Jun 06, 2005 12:56 pm     Reply with quote

You can reference the element where you want the output to appear.

In this example there is a DIV with an ID of myDiv
The date script uses this for the output.

Code:

document.getElementById('myDiv').innerHTML = str

Code:

<script type="text/javascript">
function myDate(){
var d=new Date()
var weekday=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
var monthname=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")

str = ''
str += weekday[d.getDay()] + " "
str +=d.getDate() + ". "
str +=monthname[d.getMonth()] + " "
str +=d.getFullYear()

document.getElementById('myDiv').innerHTML = str
}
</script>
<table width="400" border="1" cellspacing="0" cellpadding="2">
  <tr>
    <td width="100">
      <div align="center">
        <input type="button" name="Button" value="Click Me" onclick="myDate()" />   
      </div></td>
    <td><div id="myDiv">&nbsp;</div></td>
  </tr>
</table>
ejs7a



Joined: 06 Jun 2005
Posts: 4

PostPosted: Tue Jun 07, 2005 3:55 am     Thanks, can I ask for more help? Reply with quote

This works great, but I have another question. I would like to have say 15 of these in a table, that aren't linked together. And the date is stored in the table cell until the next time I press the Button. So say I have an update for one cell I can click that button and it inputs the date, then the next day the I want to click the other row and have that date in that row stored until the next time I click on the update button, and so on...help?
degsy



Joined: 23 Feb 2005
Posts: 2440
Location: North East, UK

PostPosted: Tue Jun 07, 2005 8:46 am     Reply with quote

You can adapt the scripts. They are just referencing ID etc.

Code:

<style>
.hidden {
visibility: hidden;
}
</style>
</head>

<body>
<script>
function show(id){
document.getElementById(id).style.visibility = 'visible';
}
</script>
<table width="200"  border="1" cellspacing="0" cellpadding="2">
  <tr>
    <td>
   <input type="button" name="Button" value="Button" onclick="show('text1')" />    </td>
    <td><p class="hidden" id="text1">This is text1
    </p></td>
  </tr>
  <tr>
    <td>
   <input type="button" name="Button" value="Button" onclick="show('text2')" />
    </td>
    <td><p class="hidden" id="text2">This is text2</p></td>
  </tr>
  <tr>
    <td>
   <input type="button" name="Button" value="Button" onclick="show('text3')" />
    </td>
    <td><p class="hidden" id="text3">This is text3</p></td>
  </tr>
</table>
jameelah1970



Joined: 09 Feb 2008
Posts: 1

PostPosted: Sat Feb 09, 2008 8:29 pm     Just a thank you... Reply with quote

[b]Thank you! Finally a date that will change with me when visitors come! I needed this for my class! :)[/i]
Display posts from previous:   
Post new topic   Reply to topic    HTML Help Forum Index -> HTML Form All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
HTML Help Archive
Powered by phpBB © 2001, 2005 phpBB Group
 
HOSTING / DESIGN
MAKE MONEY

Home
  |   Tutorials   |   Forum   |   Quick List   |   About
Copyright ©1997-2002 Idocs and ©2002-2007 HTML Code Tutorial