"BlueŽ" <superbaby@myjaring.net> writes:
[color=blue]
> I found this piece of JS which serves exactly what I need. It validates if
> the input is exactly five numberic characters.
>
> When it is validated, the form action is not carried out. What should I add
> to the code so that the form action is carried out?[/color]
[color=blue]
> P/s: I do not know JS at all.[/color]
Or HTML?
Change <input type="button" ...> to <input type="submit" ...>
However, then it will always submit. The "checkpostal" function
doesn't return any value, so there is no way for the rest of the
page to know whether the validation succeeded.
Try this:
Remeber to add a <!DOCTYPE> declaration. It is required for HTML 4.[color=blue]
> <html>
> <head>
> </head>
> <body>
>
> <script language="JavaScript1.2">[/color]
In HTML 4 and later, the "type" attribute is required. The "language"
attribute is deprecated, and should be omitted. If it is included,
don't use the version number 1.2 unless you know what the difference
between 1.2 and 1.3 is, and in which browsers it makes a difference
(i.e., just don't).
<script type="text/javascript">
function checkpostal(){
var re5digit=/^\d{5}$/; //regular expression defining a 5 digit number
if (document.myform.RecordID.value.search(re5digit)==-1) {//if match failed
alert("Please enter a valid 5 digit number.");
return false;
}
return true;
}[color=blue]
> </script>
>
> <form name="myform" ACTION="cgi-bin/dbase/dbase.cgi" METHOD="POST">[/color]
It is smarter to add validation to the submit event of the form, then
it is checked no matter how the form is submitted.
<form .... onsubmite="return checkpostal()">
[color=blue]
> <input type="text" name="RecordID" size=15>
> <input type="button" onClick="checkpostal()" value="check">[/color]
Just make it a submit button then:
<input type="submit" value="check">
[color=blue]
> </form>
> </body>
> </html>[/color]
Good luck.
/L
--
Lasse Reichstein Nielsen -
lrn@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'