trouble calling a function to validate form input

B

bbxrider

i'm trying to pass a form object to a function to validate the forms user
input
when i try to access a forms properties-like .elements[x] there is no
response from the function and no error msg, i get a screen flash
and
if i try to preset an element property before calling the function like:
this.firstName.optional=true;
the code after that doesn't get executed
going bananas, please help

to successfully call the function:
<input type="button" value="Submit Volunteer Information"
onclick="
alert('this message at start of onclick');
verify(this);">

the called function:
function verify(f) {
alert('now entering verify function');
var msg1 = "the current message is = " ;
var e = f.elements[0];
msg1 += e.type;
alert(msg1);
return false;
}
so...... i get the first alert, then nothing????

and while on the subject this code does not even get as far as the 2nd
alert:
<input type="button" value="Submit Volunteer Information"
onclick="
alert('this message at start of onclick');
this.firstName.optional=true;
alert('this message after optional assignment');
verify(this);">
 
L

Lee

"bbxrider" said:
i'm trying to pass a form object
...
<input type="button" value="Submit Volunteer Information"
onclick="
alert('this message at start of onclick');
this.firstName.optional=true;
alert('this message after optional assignment');
verify(this);">

In the context of an onClick handler, "this" refers to the
form element, not the form. Since each element has an
attribute named "form", which is a reference to its parent
form, you want to use: "verify(this.form)".
 
B

bbxrider

thanks for the help, that works, and found as well, to set an attribute of a
field, like .optional
that needs this.form as well.
i've searched high and low to find lists of properties and methods for .form
and nothing is showing up
in google groups, any suggestions where to find that documentation? and not
just for .form but all the
objects in html objects
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top