Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inserting "Time"

Status
Not open for further replies.

PittLimey

Technical User
Mar 2, 2006
2
US
I am very new to PHP, but am attempting to use PHP to populate a mysql database.

I have a form basically which allows me to manually input the current time. I have written a little javascript routine to generate the current time and I want it to write it to the field where originally I manually input it before I sql it upto the database.

Can anyone help... being new to PHP am I trying to do this the right way... should I be using javascript at all?

Here is an excerpt....

Code:
<script type="text/javascript">
function startTime()
{
var today=new Date()
var h=today.getHours()
var m=today.getMinutes()
var s=today.getSeconds()
// add a zero in front of numbers<10
m=checkTime(m)
s=checkTime(s)
document.getElementById('Time').innerHTML=h+":"+m+":"+s
}

function checkTime(i)
{
if (i<10) 
  {i="0" + i}
  return i
}
</script>
<br>

<table border=1 bordercolor=navy cellpadding=0 cellspacing=0>

	<tr>

		<td>

			<div class=TableTitle><%%DETAIL_VIEW_TITLE%%></div>

			</td>

		</tr>

	<tr>

		<td>

			<table>

				<tr>

					<td colspan=2></td>

					<td rowspan=6 valign=top>

						<div><%%INSERT_BUTTON%%></div>

						<br>

						<div><%%UPDATE_BUTTON%%></div>

						<div><%%DELETE_BUTTON%%></div>

						<div><%%DESELECT_BUTTON%%></div>

						</td>

					</tr>

								<tr>

					<td class=TableHeader valign=top>

						<div class=TableHeader style="text-align:right;"><input type="button" value="Start Time" onClick="startTime()"></div>

						</td>

					<td class=TableBody width=300><div id=Time input size=10 type=text class=TextBox name=Type_I_StartTime value="<%%VALUE(Type_I_StartTime)%%>">&nbsp;&nbsp;</div></td>

					</tr>

				</table>

			</td>

		</tr>

	</table>

Many thanks for your help..

Dave
 
Use JavaScript to do what?

Since JavaScript only runs on the client side, and your database server is on the server side, you can't use it to do any of your server-side data processing. The most you can do is use JavaScript to verify well-formed input before an HTML form field's value is submitted to a PHP script for insertion into the database.



Want the best answers? Ask the best questions! TANSTAAFL!
 
You are using a shoe to drive a nail when the hammer is sitting right next to you.

First of all, PHP has many date and time functions that can be used, without using javascript. look for the functions [blue]date()[/blue] and [blue]time()[/blue] in the php.net online manual.

Second to prepopulate the field with the current time: from PHP
just place in the text box declaration:
Code:
<input type=text name=mytime value='<? echo date("g:i:s a")?>'>
When the page is loaded the textbox will be prepopulated with the current time.


----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top