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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getting system date and time 3

Status
Not open for further replies.

visualJay

Programmer
Jun 14, 2001
57
0
0
US
Is there a way to get the date and time and place it into a input boxs or even just get them and hold them in variables.
 
Code:
var toto= new date();
gives you current date and time. Water is not bad as long as it stays out human body ;-)
 
I need to the date and time seperated and i would like to place them into an input box. can you lock the input box so the information cannot be changed.
 
Use the methods of the date object to cut it (gethour(), getminutes(), getmonth, ...).
To lock an input tag, add a disabled attribute to the tag. Water is not bad as long as it stays out human body ;-)
 
Here's an old bit of code I used elsewhere -

hope it helps some:

Code:
<head>
<script>
function dodate()
{
days = newArray(&quot;Sunday&quot;,&quot;Monday&quot;,&quot;Tuesday&quot;,&quot;Wednesday&quot;,
 &quot;Thursday&quot;,&quot;Friday&quot;,&quot;Saturday&quot;)
months = new Array (&quot;Jan&quot;,&quot;Feb&quot;,&quot;March&quot;,&quot;April&quot;,&quot;May&quot;,&quot;June&quot;,&quot;July&quot;,
  &quot;Aug&quot;,&quot;Sept&quot;,&quot;Oct&quot;,&quot;Nov&quot;,&quot;Dec&quot;)

d = new Date()
dDay = days[d.getDay()]
dMonth = monthd[d.getMonth()]

temp = dDay +&quot;,&quot;&quot;+dMonth+&quot;&quot;+d.getDate()+&quot;20&quot; + d.getYear()
document.dateform.today.value=temp
}

</script>
</head> 

<body>
<form name=&quot;dateform&quot;>
Today is
<input type=&quot;text&quot; name=&quot;today&quot; value=&quot;&quot; size=&quot;30&quot;>
</form>
<script>
dodate()
</script>
</body>


Do similiar with the time (use timeouts if you want to keep it running).

- fingerprint
 
This was what i used for the time but it says i have an error somewhere

function showhour(thehour){
if(thehour > 0 && thehour < 13){
return(thehour)
}
if(thehour == 0){
return(12)
}
return(thehour-12)
}

fuction showzero(invalue){
if(invalue > 9){
return(&quot;:&quot; + invalue)
}
return(&quot;:0&quot; + invalue)
}

function showampm(){
if(now.getHours() < 12){
return (&quot; am&quot;)
}
return (&quot; pm&quot;)
}

function showtime(){
now = new Date
document.frmcomplaint. showhour(now.getHours()) +
showzero(now.getMinutes()) +
showzero(now.getSeconds())+
showampm()
setTimeout(&quot;showtime()&quot;,1000)
}
 
having problems with your script and mine.
says missing ;
 
Fingerprint

Have fixed scripts but nothing is displayed on page how do i get this accomplished.
 
Sorry - was offline most of last night.

To put it on the screen you need the last bit of the code I
posted. Basically, you need to make a variable that holds your output first, I called mine 'temp'

So:

temp = showhour(now.getHours()) +
showzero(now.getMinutes()) +
showzero(now.getSeconds())+
showampm()
setTimeout(&quot;showtime()&quot;,1000)

then you assign temp as the value of your input field:

document.frmcomplaint. = temp

You nearly had it!

Make all your date manipulation into one big function, (I
called mine 'doDate()'), then call it after the input field in your body code.

<body>
<form name=&quot;frmcomplaint&quot;>
<input type=&quot;text&quot; name=&quot; value=&quot;&quot; size=&quot;30&quot;>
</form>

<script>
doDate()
</script>
</body>

Remember that the inital value of your field has to be null:
&quot;&quot;

- fingerprint
 
Thank you that got it working thanks for the help
 
A better way to 'lock' the text box is using JavaScript.

Code:
onFocus=&quot;blur()&quot;

add that to your input tag. Although disable does work it adds a shadow to the text and depenending on the fonts and colors you use, if any, it makes it hard to read what in the box.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top