Click to See Complete Forum and Search --> : add date & time to form input value


melsalhy
05-23-2003, 10:21 AM
When filling this particular web form, the user assigns or chooses a file name so the form results are uploaded to the server. I hope to use javascript to have the name he chooses automatically and invisibly appended based on the date and time the user presses the send button (like a prefix). This way, we eliminate the chance of overwriting files and also it provides for easy sorting and archiving. Any help would be greatly appreciated.

Example: the user chooses abc.xyz as the file name for the upload but the script actually saves it as 0523030912abc.xyz
where 05 is May, 23 is the day, 03 is the year, 09 is the hour and 12 is the minute. This way, if the user forgets and uploads a second file with the same name abc.xyz, the new time and date prefix would prevent overwriting.

I hope someone would be able to help with this idea/project. I am not asking for the upload script itself of course, I just need help with prefixing only this one form field as explained above.

<input TYPE=text NAME="FileName" VALUE="*.*" SIZE=16 MAXLENGTH=16>

Jona
05-23-2003, 11:33 AM
For security, you cannot upload files from the user's computer without the user doing it himself. You cannot use <input type="file"> as a text box for the user to upload unless he himself uploads it.

khalidali63
05-23-2003, 11:48 AM
In my opinion,your best bet will be to upload a file using javascript and prefix timestamp at the server that will recieve the file,because even if you add a timestamp to the value on the client side,I am pretty sure that file element has its own security setup which will not let you change its value with JavaScript.

melsalhy
05-23-2003, 01:40 PM
Dear Jona and Khalid,
The form actually works already on my server via a java applet where the visitor records a sound file, gives it a name (hence the question I posted), then sends it (posts it) to the server where it resides in a specified directory. If he re-visits the page and records or creates a new file and gives it the same name he picked for the previous one, it will overwrite the older one. That's why I hoped we can intervene using javascript invisibly to assign the said prefix based on the user's local time and date to prevent overwriting and also help sorting as I explained.

So,, after this clarification, anything could be done??? :confused:

khalidali63
05-23-2003, 01:49 PM
I have put this thing together you can use it for your need,to be honest with you,I am still lost..:-)

http://68.145.35.86/skills/javascripts/FormatFileNameDependingUponTime.html

melsalhy
05-23-2003, 03:18 PM
Dear Mr. Khaled Ali,
I visited the URL you kindly offered and I sincerely appreciate your cooperation. However, this won't work since in your scenario you are pulling a file from the local client's computer with the "Browse" button but in my case, the java applet itself creates (records) the file and saves it to the server.

Please visit http://www.canadacare.net/recorder/rec_app1.html to see what I mean to alleviate the vagueness. When prompted, please accept the small applet.

Any further help or insight you can offer would be tremendously appreciated.

Thanks and best regards.

Mohamed Elsalhy:rolleyes:

khalidali63
05-23-2003, 03:28 PM
:-)

The point of creating that script was that to help you with the concept that how it may be done,(prefixing the timestamp in js),by looking at your page,you do almost exactly what I have done,only difference is that when a user submits,I get the file name from the file upload field,in your case you will need to get the name from the "FileName"

something like this

var filename = document.Gui_RP.FileName.value;

once you have the file name you will pass it to the function I created and it will prefix the time stamp to the file name and onceits done you can submit it as you already are doing..