Re: javascript and forms
by "Cyanide _7" <leo7278(at)hotmail.com>
|
Date: |
Tue, 18 Jan 2000 04:57:13 CST |
To: |
jrstanford(at)home.com |
Cc: |
hwg-languages(at)hwg.org |
|
todo: View
Thread,
Original
|
|
try this:
<html>
<head>
<title>
Form Testing Page
</title>
<script language="javascript" type="text/javascript">
<!-- Hide script from older browsers
function checkForm(testform) {
var valid = true;
if (testform.name.value ="") {
alert ("You must enter your name in the required field.");
testform.name.select(); // automatically focuses to select
valid = false;
}
return valid; //return valid to continue or cancel submition
}
// end hiding from older browsers -->
</script>
</head>
<body leftmargin="50">
<form name="testform" action="mailto:jrstanford(at)home.com"
method="post" onSubmit="return checkForm(testform);">
<table cellpadding=2>
<tr>
<td></td>
<td><font type="sans serif" size="5"><b>FORM
TESTING</b></font></td>
</tr>
<tr>
<td align="right">Name</td>
<td><input type="text" size="40" name="name" value=""> *</td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Submit"> <input
type=reset></td>
</tr>
</table>
</form>
</body>
</html>
i'm guessing your problem was that tmp was undefined, and it didn't stop the
submition... granted the code only allows for checking ONE required field,
it will work. - Cyanide_7
>-------------------------------------------
>From: "Jim Stanford" <jrstanford(at)home.com>
>To: "hwg-languages" <hwg-languages(at)hwg.org>
>Subject: javascript and forms
>Date: Tue, 18 Jan 2000 03:56:00 -0600
>
>I've been having a terrible time trying to make sense of creating a form
>using input validation. Below is a sample of the code (pardon the mess, I
>could not get it to come over formatted).
>
>I am sure the problem has to do with my not understanding how the DOM
>works,
>but nothing I have read seems to be truly clear on this. Any help is
>appreciated.
>
>Jim Stanford
>
>
>
><html>
> <head>
> <title>
> Form Testing Page
> </title>
><script language="javascript" type="text/javascript">
>
><!-- Hide script from older browsers
>
>function checkForm(testform) {
> if (document.testform.name.value ="") {
> alert ("You must enter your name in the required field.")
> tmp.focus()
> tmp.select()
> }
>}
> // end hiding from older browsers -->
>
></script>
>
></head>
><body leftmargin="50">
>
><form name="testform" action="mailto:jrstanford(at)home.com" method="post"
>onSubmit="checkForm(testform)">
>
><table cellpadding=2>
> <tr>
> <td></td>
> <td><font type="sans serif" size="5"><b>FORM
>TESTING</b></font></td>
> </tr>
> <tr>
> <td align="right">Name</td>
> <td><input type="text" size="40" name="name" value="">
>*</td>
> </tr>
> <tr>
> <td></td>
> <td><input type="submit" value="Submit"> <input
>type=reset></td>
> </tr>
></table>
>
></form>
></body>
></html>
>
>
>
______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com
HWG: hwg-languages mailing list archives,
maintained by Webmasters @ IWA