By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,483 Members | 1,052 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,483 IT Pros & Developers. It's quick & easy.

trouble calling a function to validate form input

P: n/a
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);">
Jul 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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)".

Jul 20 '05 #2

P: n/a
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

"Lee" <RE**************@cox.net> wrote in message
news:bg*********@drn.newsguy.com...
"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)".

Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.