If you have a validation function in yoru greasmonkey script,
myValidate(), which returns false if bad data is entered into some
form, someForm, on the page, how can you use the myValidate() function
to prevent the form from being submitted?

Here are details, including what I've tried and (I think) I've learned
so far.

On a particular page, I want a greasemonkey script to validate the
data I put into a form.  Basically I would like to do something like
this:
<code>
    someForm.setAttribute("onsubmit","return myValidationFunction()");
</code>

...but this does not work, I believe for reasons explained here:
http://www.oreillynet.com/pub/a/network/2005/11/01/avoid-common-greasemonkey-pitfalls.html?page=3
(Pitfall #2 "Event Handlers").

I try the solution suggested in the above link:
<code>
  someForm.addEventListener("submit", myValidationFunction, true);
</code>

This gets closer, as submitting the form will call my function.  But
it does not block submission of the form if it returns false.  This is
because the onsubmit attribute needs the word "return" to make it
block submission based on a return value from the validation function.

Is there a way to do this?

-- 
You received this message because you are subscribed to the Google Groups 
"greasemonkey-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/greasemonkey-users?hl=en.

Reply via email to