button to force text change

F

Fred

I have a form field that displays a date from a database. I would like a button that inserts today's date/time if the imported data is null (to be submitted later to update the database). I do not want the null data updated unless the button is clicked. Once the date is displayed, the button should have no further effect. I can handle the asp code to access/submit the data, but the button functionality escapes me
I am using Frontpage 2002, asp, vbscript
Thanks
Fred
 
J

Jon Spivey

Hi Rhonda,
Not wanting to put you off but that's really not good. The idea of checking
if the date is null is sound but
1/ you should never address any object on a page with document.all Thats IE
only, any other browser will either ignore it or error out. To address a
form object cross browser you'd use
document.formname.fieldname
or
document.forms[0].fieldname
2/ If you want to check for a null date it should be done on the server not
the client - this way we cover people who have js turned off.
3/ A javascript date object would be something like
Tue Apr 27 19:44:47 UTC+0100 2004
you cannot put this into a database datetime field A database accepts a
date as mm/dd/yyyy or dd/mm/yyyy etc to be safe regarding different
countries you'd want yyyy-mm-dd

I think the answer would be if youre willing to lose non js users
<input type="text" name="T1">
<input type="button" onclick="setDate(this.form)" value="set date">
function setDate(f){
d=new Date();
f.T1.value=d.getFullYear()+'-'+pad(parseInt(d.getMonth()+1))+'-'+pad(d.getDa
te());
}
function pad(s){
return (s<10)?'0'+s:s;
}

or to round trip to the server to get the date
 
S

Skydolphin

For that matter, since you are loading the page from a database anyway, why don't you just check to see if the datafield is null and then load the text box with the current date as the page is loading. Are you using VBScript on the server

Rhonda
 
J

Jon Spivey

From the original post - "I am using Frontpage 2002, asp, vbscript"

I think the requirement is to populate the date form field only when the
user wants to - ie not automatically. Hence my response to either populate
the date field with javascript when the button is clicked or round trip to
the server to get the date. Important point being the date has to in a
format the database will accept and any client side script has to populate
the form field in a way that will work in any browser - it doesnt make sense
to use IE only code to do something that is easy to do cross browser

VB Script (on the server) doesn't do anything while the page is loading - it
generates html to send to the browser. The browser then loads the page. The
only way to alter the page while it's loading is with client side script -
usally javascript.
 
F

Fred

Thank you all for the quick response. The purpose of the update via button is to differentiate between a manager who may view the page and an engineer who acknowledges receipt by pushing the button. I had not thought of passing the form object as an argument - guess I have been away from programming too long
Fred
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top