Pls Help. assinging system date to a text box.

Results 1 to 2 of 2

Thread: Pls Help. assinging system date to a text box.

  1. #1
    nath Guest

    Default Pls Help. assinging system date to a text box.

    I have 2 text boxes on a .ASP screen. The first text box is user enterable date<BR>and the second text box is disabled and once the submit button is hit the second text box should<BR>be populated with the system date & time. I have written code in Javascript to populate the second text box with system date & time. But it gives me some vague error. I am not able understand whats the mistake I am doing.<BR><BR>I have written the code like this.<BR><BR>&#060;HTML&#062;<BR>&#060;HEAD&#062;< BR>&#060;SCRIPT LANGUAGE="JavaScript"&#062;<BR> function form_Validations(theform) {<BR> <BR> //Code to validate the first text box&#039s content. Works fine.<BR><BR> // Code to assign system date to the second text box. Gives error somewhere else.<BR> dim today = New Date();<BR> theform.txt_secondbox.value = today;<BR> return True;<BR> }<BR>&#060;/SCRIPT&#062;<BR>&#060;Body&#062;<BR>&#060;Form action=a.asp name=form1 method=post onsubmit="return form_validation(this)"&#062;<BR><BR>&#060;/form&#062;

  2. #2
    Join Date
    Dec 1969

    Default RE: Pls Help. assinging system date to a text bo

    What your difficulty was was you were trying to put an object into a string field. You need to use one or several methods of the Date object in order to get the result you desire. Heres the code to return the GMT time as a string. Mind you that you can also get each part of the date separately ie. getMonth, getYear(getFullYear), getDate,getMinutes,getHours...yada,yada. Here&#039s the code:<BR><BR>function dothis()<BR>{<BR> var mydate = new Date()<BR> document.forms[0].text1.value = mydate.toGMTString();<BR>}<BR><BR>Hope this helps. Good Luck.<BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts