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

Insert current time

Status
Not open for further replies.

evr72

MIS
Dec 8, 2009
265
US
Hello,

I wrote a script to insert the current time on a field depending on another field

for example if my field "start" = "Now" then my field "pick_start_time" should get the current time

what my script is doing when "start" = "Now" I get redirected to a blank page with the time on it
not sure how to get the time on my "pick_start_time" field

here is what I have so far
Code:
var tName = 'pick';
var ctrlkeycontrol = Runner.getControl(pageid, 'start'); 
var ctrlkeycontrol02 = Runner.getControl(pageid, 'stop');
var ctrlresp = Runner.getControl(pageid, 'pick_start_time'); 
var ctrlresp02 = Runner.getControl(pageid, 'pick_finish_time'); 
function func() {

var currentTime = new Date()
var hours = currentTime.getHours()
var minutes = currentTime.getMinutes()
if (minutes < 10){
minutes = "0" + minutes
}
document.write(hours + ":" + minutes + " ")
if(hours > 11){
document.write("PM")
} else {
document.write("AM")
}
 };
if (ctrlkeycontrol.getValue() == 'Now')
ctrlkeycontrol('==', func);
 
You are not getting redirected to a blank page, what document.write does is it overwrites everything in the page with the value you pass it.

Instead of using document.write, use the value property of your field. For instance:

Code:
document.getElementById('myfield').value=hours + ":" + minutes;

...
<input type=text id="myfield">

----------------------------------
Phil AKA Vacunita
----------------------------------
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.

Behind the Web, Tips and Tricks for Web Development.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top