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

Submitting a form and onSubmit Validation?

P: n/a
I just noticed that if I use a "submit" button the "onSubmit" function call
will be invoked. But if I use a button to call some other javascript and at
the end of that javascrip I do something like "form.submit()" the "onSubmit"
function call will NOT be invoked. I thought that was wierd. Can anyone
shed some light? Here's a small example:

<script type="text/javascript">
function subform()
{
document.frm1.submit();
}
function checkform()
{
alert('checking form');
return true;
}
</script>
</head>

<body>
<form name="frm1" method="post" action="" onSubmit="return checkform();">
<input type="text" name="txtname"><br>
<input type="submit" name="btnsubmit" value="submit"><br>
<input type="button" name="btn1" value="go" onClick="subform();">
</form>
</body>

-Bruce Duncan

Jul 23 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
If your code is explicitly calling the submit method, then it should be able
to do form validation work before calling it.

The logical conclusion is to change your <input type="submit" to <input
type="button" thereby having one entry point for doing your onsubmit/forma
validation work.
--
Peter O'Reilly
Jul 23 '05 #2

P: n/a
"Peter O'Reilly" <Pe***********@timeinc.com!N!O!.S!P!AM!> wrote in message
news:cf**********@inntp-m1.news.aol.com...
If your code is explicitly calling the submit method, then it should be able to do form validation work before calling it.

The logical conclusion is to change your <input type="submit" to <input
type="button" thereby having one entry point for doing your onsubmit/forma
validation work.
--
Peter O'Reilly

I thought doing form.submit() was just the same as "clicking a submit
button?" I guess not. Your conclusions are correct and I would do
something like that if I were working on a problem. I just happen to notice
this "feature" and thought it was wierd. Thanks for your input.

-Bruce Duncan

Jul 23 '05 #3

P: n/a
> I just happen to notice this "feature" and thought it was wierd. Thanks
for your input.

I understand your comments full well. Keep in mind though that this
behavior is consistent across web browsers and
is part of the Netscape language specification for JavaScript, if I'm not
mistaken. If not JavaScript then the ECMA specs
(I'm admittedly too lazy to re-look up) and most definitely in the
"javascript: The definitive guide" book (which I highly recommend).
--
Peter O'Reilly
Jul 23 '05 #4

P: n/a
"Peter O'Reilly" <Pe***********@timeinc.com!N!O!.S!P!AM!> wrote in message
news:cf**********@inntp-m1.news.aol.com...
I just happen to notice this "feature" and thought it was wierd.
Thanks for your input.

I understand your comments full well. Keep in mind though that this
behavior is consistent across web browsers and
is part of the Netscape language specification for JavaScript, if I'm not
mistaken. If not JavaScript then the ECMA specs
(I'm admittedly too lazy to re-look up) and most definitely in the
"javascript: The definitive guide" book (which I highly recommend).
--
Peter O'Reilly


How right you are Peter...
Page 573...Javascript the definitive guide...4th ed

....had only I read this first...

-Bruce Duncan

Jul 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.