[thelist] javascript & forms
Jeff
jeff at members.evolt.org
Mon Apr 3 02:19:28 2000
james,
:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: From: James Spahr <james@designframe.com>
:
: is there a way to catch when someone types a return
: character into a text field in a form?
:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
one way would be to simply put an additional form on the page, then the
enter key will no longer work as a submit (so they say).
:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: They never wind up in the value of the form element - I'd
: like to catch when someone types it and adjust the focus
: of the document ...
:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
just do a simple onSubmit validation, returning false if the form doesn't
have anything entered in it.
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
function validateForm(form)
{
if(form.username.value == '')
{
alert('This field is required. Please enter your username.');
form.username.focus();
return false;
}
else
{
return true;
}
}
// -->
</SCRIPT>
then, your form might look like this:
<FORM
NAME="myLogin"
onSubmit="return validateForm(this)">
<INPUT
TYPE="TEXT"
NAME="username"
SIZE="10"
VALUE="">
</FORM>
good luck,
.jeff
name://jeff.howden
game://web.development
http://www.evolt.org/
mailto:jeff@members.evolt.org