To expand on Wayne's answer:
Javascript runs off of id="" tags. Names do it no good at all.
Technically you should be giving EVERY tag an ID that can carry one.
Anytime you want to manipulate a specific object with Javascript you
are going to refer to it by its ID. Prototype allows you to do neat
things like grabbing all objects with a specific class, or
"navigating" the DOM tree by going up or down a level from an object,
but the safest and easiest way is to use ID tags, and that's what the
Validation framework requires to work properly, which is one reason
why you're getting that error.
Secondly, the reason the JS has to come AFTER the form is that when
the JS runs in your current code, the form doesn't exist yet. The
browser will be throwing a silent error because you're trying to
attach Javascript to something that hasn't yet been rendered. What
Wayne's code is doing is telling Javascript to wait until the page is
done loading (thereby the form WILL exist) THEN call/create the
validation, which works just as well and as he said lets you keep your
javascript all up in the head. Personally I leave it at the bottom of
my form document so that it runs right after the form loads, since if
you wait on the rest of the page people could technically enter data
before the validation has started and submit the form, though this
depends heavily on how quickly the page loads.
Hope this helps some.
On Jul 22, 4:24 pm, Wayne Leroux <wayneler...@gmail.com> wrote:
> Hey,
> Move:
> <script type="text/javascript">
> var checker = new Validation('laura_namelist_data',
> {onSubmit:false});
> </script>
> AFTER the form
> and change:
> <form name='laura_namelist_data'>
> to:
> <form name='laura_namelist_data' id='laura_namelist_data'>
> Personally... I rather have the validation code up in the head with
> the other javascript:
> Event.observe( document, 'load', function(){
> new Validation('laura_namelist_data', {onSubmit: false});
> });
> Hope this helps,
> - Wayne Leroux
> On 22-Jul-08, at 4:16 PM, nam5a wrote:
> > This does not work. Can anyone help??? It says $(form) has no
> > properties
> > <script type="text/javascript">
> > ...
> > function valid() {
> > return checker.validate();
> > }
> > function process(form){
> > if (valid())
> > {
> > ...
> > }
> > </script>
> > ...
> > <form name='laura_namelist_data'>
> > <script type="text/javascript">
> > var checker = new Validation('laura_namelist_data',
> > {onSubmit:false});
> > </script>
> > ...
> > <input type ="button"
> > value="write laura_namelist_data"
> > onclick="process(this.form)"/>
> > </form>