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!

Date and time 2

Status
Not open for further replies.

chassid

MIS
Aug 27, 2000
58
0
0
US
B"H

I would like to know how do you enter the date and time a form was completed automatically when the user presses the submit button. The information should be submitted to an access database connected through ODBC.

Also, I want a textfield to be populated after the user chooses a company on a drop down list.

Any help in figuring this out will be greatly appreciated.

Daniel

Do you know the Chabad Lubavitch Sheliach in your area?
He is waiting for you!
 
see
for date/time function information

<script language=&quot;javascript&quot;>
function dateTime(){
var myDate = new date();
document.myform.dateTime = myDate.getHours() + ':' + myDate.getMinutes() + ':' + myDate.getSeconds();
return true;
}

function watchChg(i){
switch(i){
case 0: document.myform.mytxt.value = &quot;something&quot;; break;
case 1: document.myform.mytxt.value = &quot;this&quot;; break;
case 2: document.myform.mytxt.value = &quot;somethign&quot;; break;
}
}
</script>


<form name=&quot;myform&quot; action=&quot;someASP.asp&quot; onsubmit=&quot;return dateTime();&quot;>
<input type=&quot;hidden&quot; name=&quot;dateTime&quot; value=&quot;&quot;>
...
<select name=&quot;chg&quot; onchange=&quot;javascript:watchChg(this.selectedIndex())&quot;>
<option>my first option</option>
<option>my second option</option>
<option>my third option</option>
</select>
<input type=&quot;text&quot; name=&quot;myTxt&quot; value=&quot;&quot;>
<input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;click me&quot;>
</form>

hth
leo leo
 
If you just want to know when the user submitted the information, there 2 other ways to do it.

1. create a hidden input field with a value of Now()
<input type=hidden name=date_time value=<%=now()%>>
This will pass the current system date to the next page when you submit, but it will only pass the date/time when the page was loaded.

2. Just add the Now() command to your insert statment. If you are using a actual SQL statment just appened the statment to include the new field and it's value.

SQL=&quot;Insert into mytable (date_submitted, name, etc...) values (now(), 'John Doe', etc.....)&quot;

or simply
MyRS.AddNew
MyRS(&quot;date_submitted&quot;) = Now()
MyRS.Update

This might be a little easier than using the command listed above, but what he has will work.
 
Dynapen,

I have a question for you too regarding date... how to format date Now() to be just the date and not include the time.

I was thinking of using the date to compare in the database once a record is added to prevent duplication of records from a user. Because as it stands right now, after the record has been added, they will get to see the info they have added. But if they click on the Refresh button, they will accidentally add another record to the database. Thought I'd compare the date and use it to prevent that.

Mary :)

Rule 1: Don't sweat the small stuff.
Rule 2: EVERYTHING is small stuff!! X-)
 
That was WAY too simple!! *G* Thanks! Mary :)

Rule 1: Don't sweat the small stuff.
Rule 2: EVERYTHING is small stuff!! X-)
 
Create a hidden field and give the value as
<input type=&quot;hidden&quot; value=&quot;<%=now()%>&quot; name=&quot;hvalue&quot;>

Once the form was submitted to other page do the coding
<%
dim v=request(&quot;hvalue&quot;)
set mycon=server.createobject(&quot;Adodb.connection&quot;)
mycon.open &quot;file.DSN&quot;
sql=&quot;insert into table values('&quot;v&quot;')&quot;
mycon.execute sql
mycon.close()

%>

 
Or better still,
set the default value in your access table for that date column, as Now() or GETDATE() if SQL Server.

And forget about that particular column in your INSERT statement..It will be taken care of. Thank you...
RR

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top