[Javascript] newbie function question

Rodney Myers rodney at aflyingstart.net
Fri Aug 16 13:30:50 CDT 2002


Katrina,

<form onSubmit="myFunction(this)" etc >

Then in your script

function myFunction(form){
....
}

Note that the parameter 'form' is just a name, but an obviously convenient one.
What matters is that the function was passed the form object

If you wanted to invoke the function from a button

<input type="button" onClick="myFunction(this.form)"

You might appreciate my form examples at
http://www.aflyingstart.net/course_demos/

hth

Rodney


Katrina Geevers-Collins wrote:

> rodney,
>
> thanks for the advice, but how do i tell the function what form to use, in
> case there is more than one form on the page?
>
> (i told you i was a newbie)
>
> -----Original Message-----
> From: javascript-admin at LaTech.edu [mailto:javascript-admin at LaTech.edu]On
> Behalf Of Rodney Myers
> Sent: Thursday, August 15, 2002 9:32 AM
> To: javascript at LaTech.edu
> Subject: Re: [Javascript] newbie function question
>
> Matthew, for a reuseable function of this sort I would recommend that you
> just
> pass the form object.
>
> Within the function all element names and types can be found from the
> form.elements array
>
> The first element in the array is form.elements[0]
> Its name is form.elements[0].name
> Its type is form.elements[0].type
> Its value is form.elements[0].value
>
> If you create an associative array based on actual element names you can
> create
> data which can control your function. e,g on the matter of required fields,
> required input lengths even formats.
>
> But what is most important is to have something simple, that works and on
> which
> you can later build, perhaps along lines of my suggestion.
>
> hth
>
> Rodney
>
> Matthew Collins wrote:
>
> > hi all,
> >
> > i'm trying to write a function to validate a form.  problem is, i want the
> > function to be reusable on many pages, so one of the variables passed to
> the
> > function is the form name, while the other variable is the name of the
> > fields to be checked.
> >
> > problem is, i'm getting an error that the "'document.FormName.formArray'
> > does not exist"
> >
> > here's the javascript:
> >
> > <script language="JavaScript">
> >
> > <!--
> > function IsFormComplete(FormName,formFields)
> > {
> > var x       = 0
> > var formArray = formFields.split(",");
> >
> > for (x=0; x < formArray.length; x++)
> >    {
> >         if (document.FormName.formArray[x].value == '')
> >      {
> >         alert('Please enter the '+document.FormName.formArray[x].name +'
> and
> > try again.')
> >         document.FormName.formArray[x].focus()
> >      }
> >    }
> > }
> > // -->
> >
> > </script>
> >
> > *and the html of the form*
> > <form method="POST" action="formTest.asp" name="form"
> > onsubmit="IsFormComplete('form','T1,S1,C1');">
> >
> > thanks in advance,
> >
> > _______________________________________________
> > Javascript mailing list
> > Javascript at LaTech.edu
> > https://lists.LaTech.edu/mailman/listinfo/javascript
>
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
>
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript





More information about the Javascript mailing list