[thelist] JavaScript - form.submit()

Jeff Howden jeff at members.evolt
Fri Jul 28 17:38:30 CDT 2000


scott,

:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: From: <Scott_Brady at themoneystore.com>
:
: I'm having problems with using the submit() function
: on a form in JavaScript.
:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

good.  *grin*

you shouldn't be using the submit() method at all.

:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: If anyone has any ideas, I'd be grateful.
:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

sure, got lots of them.. not sure how many of them apply to your predicament
though.

:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: < form
:    action="index.cfm?FA=<cfoutput>#attributes.RFA.add#</cfoutput>"
:    method="post"
:    name="addJobForm"
:    onSubmit="verifyForm(this); return false;">
:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ok, you're already doing part of the right thing by using the onSubmit event
handler of the form.  the wrong thing that you're doing returning false
immediately after calling the function.  instead, you need to request that
the verifyForm() function return a boolean to either allow or prevent
submission based on the validity of the data.

onSubmit="return verifyForm(this)"

now, instead of using the submit() method at the end of the function if
everything checks out, you simply return true and the form will submit.

one other thing.  instead of doing a long if/else if/else validation
routine, just use a whole chain of if() statements and put the return true
statement outside of all of it at the bottom of the function just before
closing the function.

here's an example of what i mean (pseudo code):

function verifyForm(form1)
{
  if(value)
  {
    alert('error message');
    focus;
    select;
    return false;
  }
  if(another value)
  {
    alert('error message');
    focus;
    select;
    return false;
  }
  return true;
}

good luck,

.jeff

name://jeff.howden
game://web.development
http://www.evolt.org/
mailto:jeff at members.evolt.org






More information about the thelist mailing list