[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.frontpage.programming

button to force text change

=?Utf-8?B?cm9kY2hhcg==?=

4/27/2004 12:11:00 PM

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
5 Answers

Jon Spivey

4/27/2004 7:15:00 PM

0

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

--
Cheers,
Jon
Microsoft MVP - FP



Skydolphin wrote:
> Instead of forcing someone to click a button if the field is null,
> why don't you just run a javascript function the checks to see if the
> textbox is blank and then put the current date in it?
>
> function checkDate()
> {
> currDate=new Date();
> if (document.all("T1").value == "")
> {
> document.all("T1").value = currDate;
> }
> }
>
> You could run the function on the onload event.
>
> <body onload="checkDate()"; >
>
>
> Rhonda


=?Utf-8?B?cm9kY2hhcg==?=

4/27/2004 9:31:00 PM

0

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

Jon Spivey

4/27/2004 10:01:00 PM

0

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.

--
Cheers,
Jon
Microsoft MVP - FP

Skydolphin wrote:
> 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


=?Utf-8?B?cm9kY2hhcg==?=

4/27/2004 10:46:00 PM

0

I guess I must have misunderstood the original post.

=?Utf-8?B?cm9kY2hhcg==?=

4/28/2004 7:06:00 AM

0

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