|
Posted by daniel kaplan on December 12, 2004, 6:10 pm
Please log in for more thread options
hello all,
am new to HTML and am in the process of creating a form, no serious
headaches, but am stumped on two types of fields. i can take care of these
situations using javascript, but was adviced to only use javascript only
when absolutely necessary, so am trying to find to see if i can handle these
situations in HTML only.
TEXTAREA field
maxlength isn't doing anything, is there a solution?
DATE
is there a way to create a DATE field that only accepts numbers and "/". i
have found tons of sites that say input="date" or date="mm/dd/yyyy", but
they do nothing!
if in the end i have to do all my validating via javascript or server side,
so be it, but wanted to check out here first.
many thanks ahead of time,
daniel
|
|
Posted by David Dorward on December 12, 2004, 11:47 pm
Please log in for more thread options
daniel kaplan wrote:
> am new to HTML and am in the process of creating a form, no serious
While writing words entirely in capital letters is an accepted form of
emphasis, they should also be used to start sentences. It makes it rather
harder to read a message which lacks capitals in the usual places, so
please help us to help you.
> headaches, but am stumped on two types of fields. i can take care of
> these situations using javascript, but was adviced to only use javascript
> only when absolutely necessary
JavaScript is not something that should be used only when there is no other
way. It can be used for many things, but should never be _depended_ upon
(and generally shouldn't be used when the effect can be achieved in plain
HTML 4.01 Strict or CSS).
> TEXTAREA field
> maxlength isn't doing anything, is there a solution?
> DATE
> is there a way to create a DATE field that only accepts numbers and "/".
There is nothing in HTML to enforce the format of text entered into a
textarea field, nor is there anything to suggest a maximum length of a
textarea. JavaScript could be used in both these cases to aid the user in
entering data to fit the requirements of the system.
Even the HTML suggestions are only suggestions, there is nothing actively
preventing the user from entering whatever data they like - so you should
*always* perform sanity checking of incoming data on the server.
On the subject of the date, my preferred method for handling this type of
thing is a normal text input for the user to enter the date. Next to this I
(having checked that the browser supports enough JavaScript, CSS and DOM to
handle it) I place a calendar icon set to fire off a JSCalendar[1] which
writes the date out in an unambiguous format[2]. On the server I then run
the date through Date::Parse[3] which can cope with most date formats a
user might choose to use.
[1] http://www.dynarch.com/projects/calendar/ [2] e.g. 12th Dec 2004
[3] http://search.cpan.org/~gbarr/TimeDate-1.16/lib/Date/Parse.pm
--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/> Home is where the ~/.bashrc is
|
|
Posted by daniel kaplan on December 12, 2004, 7:11 pm
Please log in for more thread options
[many things]
Thanks for your help, if i may ask a follow up:
Woudl it be wiser to use BOTH JS and server-side to validate the data? I
mean sure, I could use JS to do that, but then wiseguys (i assume) could
manipulte outgoing data, and then lets face it, not validating at the server
side would just be crazy.
So my thoughts are, validate at the client-side (using JS) to elminate 95%
of server-side processing time, by catching innocent mistakes, and then
still validate at server-side to prevent the trouble makers.
Woudl my thinking be correct here?
Thanks agaiun,
daniel
|
|
Posted by David Dorward on December 13, 2004, 12:28 am
Please log in for more thread options daniel kaplan wrote:
> Woudl it be wiser to use BOTH JS and server-side to validate the data?
I thought I've covered this in my previous post, but rereading it I find
that I only implied it, so here goes:
If its important the the data you receive fit a certain format (and it very
often is, even if only to avoid losing data that won't fit in the given
space in a database column) then you *should* perform some form of check on
the server and return an error message (or maybe just a wanring) to the
user if it fails.
*Optionally*, after[1] you have written the server side code, you can look
at providing some client side check (using the maxlength attribute and/or
JavaScript) as a *convenience* to the user so that they can receive the
afore mentioned error or warning without having to spend time watching
their form submission make a round trip to the server and come back with
errors.
[1] You could do it before, but leaving it until after helps avoid lazyness
and accidently dependency on the client side code.
--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/> Home is where the ~/.bashrc is
|
|
Posted by Michael Winter on December 13, 2004, 12:01 am
Please log in for more thread options wrote:
[snip]
> i can take care of these situations using javascript, but was
> adviced to only use javascript only when absolutely necessary,
You can use client-side scripting as often as you like. The caveat is that
you must not *rely* on it (at least on the Web) to perform validation or
provide critical functionality (like navigation). You can use Javascript
to validate a form, but that validation should be replicated on the server.
[snip]
> TEXTAREA field
> maxlength isn't doing anything, is there a solution?
There is no maxlength attribute for TEXTAREA elements. You'll have to
check the length of the string on submission.
> DATE
> is there a way to create a DATE field that only accepts numbers and "/".
No.
> i have found tons of sites that say input="date" or date="mm/dd/yyyy",
> but they do nothing!
Then tons of sites contain complete rubbish (nothing unusual there, then).
:) Again, it's something you'll have to validate yourself, though be
careful with using locale-specific date formats if you'll draw audiences
from other countries.
[snip]
Mike
--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
|
| Similar Threads | Posted | | LAST_MODIFIED Date | June 23, 2007, 9:18 pm |
| date format in forms? | July 15, 2004, 12:54 am |
| Is there a way to get web page creation date? | February 10, 2005, 12:30 pm |
| last modified date of a web page? | March 8, 2005, 1:15 pm |
| Ho to get (and format) today's date? | July 20, 2006, 1:43 pm |
| What's the Date object using JavaScript? | December 13, 2008, 3:27 am |
| How to code "content-disposition" so that file modification date is maintained? | April 22, 2006, 6:30 pm |
| Can searching be customized -- To focus search-results & find up-to-date content? | August 1, 2006, 9:50 pm |
| March 3, 2005, 2:11 pm |
| IE TextArea Display Bug | January 12, 2005, 10:16 am |
|