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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to format a date as it is being entered? 1

Status
Not open for further replies.

Number6

Programmer
Jul 5, 2000
9
US
Here is the problem: A text field represents a date.  If the first character entered is 9, then the field should automatically change to look like 09/.  If the first character entered is 1, then nothing happens until the second character entered is 0, 1 or 2.  For example, if 1 is the next character, then it looks like 11/.  If the next character entered is a 4, then the field looks now looks like 11/04/.  Is there some algorithm for this type of process?  There are many combinations.
 
u can use this <br><br>&nbsp;variable1 = cdate(variable2)<br>&nbsp; <p>Unicorn11<br><a href=mailto:webmaster@tripmedia.com>webmaster@tripmedia.com</a><br><a href= > </a><br>Hi there it all likeminded fellows!!!!!!
 
I do not think that I explained the problem correctly.&nbsp;&nbsp;I apologize.&nbsp;&nbsp;As the field is being filled, the format must change.&nbsp;&nbsp;I believe cdate returns a formated date, which would mean that the date field has to be filled cpmppletely.&nbsp;&nbsp;Correct me if I am wrong but this is what I am trying to do.&nbsp;&nbsp;A user enters the first character 9, the field on the window now shows 09/.&nbsp;&nbsp;Next the user types in 4.&nbsp;&nbsp;The window now shows 09/04/ and is ready to accept either a two or four character year (00 or 2000 for example).&nbsp;&nbsp;This is only one type of case.&nbsp;&nbsp;Here is another example.&nbsp;&nbsp;The user types in 1 and nopthing changes.&nbsp;&nbsp;The user types in 2 and now the window column look like 12/.&nbsp;&nbsp;Next the user types in 2 and the window column looks like 12/2 and nothing happens until the user types in 5 and the window column now looks like 12/25/.&nbsp;&nbsp;If I am mistaken, would you please describe to me what I am misinterpretating.&nbsp;&nbsp;This is a very confusing problem for me.
 
You're going to have to react to the onChange or onKeypress events.&nbsp;&nbsp;This isn't a trivial exercise, because you'll also have to deal with the fact that some countries use different date formats,&nbsp;&nbsp;and also that user can use the arrow keys to position themselves where ever they want to be within the date string,&nbsp;&nbsp;and delete one or more characters (or all of them) before they add a new one.<br><br>This is the reason that many web sites, when asking for dates, simply use different fields for month, day and year, and make the user select each one separately.&nbsp;&nbsp; <p>nick bulka<br><a href=mailto: > </a><br><a href= > </a><br>
 
Another approach could be to show an example of how the date <i>should</i> be formatted right above the text field then check the formatting with js with an onClick in the submit button and show an alert if the user input isn't correctly formatted:<br><br>Please enter date: (eg. 06/16/97)<br><br>The easiest way however is probably to use a little drop down menu for each value like Nick suggested above. <p>--Will Duty<br><a href=mailto:wduty@radicalfringe.com>wduty@radicalfringe.com</a><br><a href= > </a><br>
 
Nick and Will,<br><br>Thank you for this information.&nbsp;&nbsp;Unfortunately, I agree with you that this is not just a simple case of making a quick adjustments, such as adding a drop down menu.&nbsp;&nbsp;My client has a system built and I am just doing some modifications to it.&nbsp;&nbsp;I thought that the problem involves a lot of what Nick describes in his suggestion, but it even goes beyond that for combinations of values.&nbsp;&nbsp;There are many issues in this modification and I agree that the parts of the date should have been broken out, but that it out of my control. <br><br>Right now, when I enter a value such as 9 for the month, the field changes to 09/ which is correct, but the cursor repositions itself to before the &quot;0&quot; and not after the &quot;/&quot;.&nbsp;&nbsp;How/ why does this occur and is there a way to reposition the cursor to the end of the entered value?&nbsp;&nbsp;This would be a great start, since I believe that I could always get the actual length of the field before the next character is entered. With the length and the cursor in the correct position, I think that this is as good as any place to start.&nbsp;&nbsp;I know that the back arrow conditions will/ macause a problem, but this is secondary for now.&nbsp;&nbsp;If you have any more suggestions, please feel free send/ post them (as often as possible).<br><br>Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top