473,385 Members | 2,014 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Submitting a form and onSubmit Validation?

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
4 12379
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
"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
> 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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: CJ | last post by:
Why won't this work? I am passing the name of the form (I have two that use this validation script) but I keep getting an error. Error reads: "document.which_form.name is null or not an object" ...
2
by: Greg T | last post by:
Hi, I have a rather long form that I don't want people submitting unless they are absolutely sure they are ready. I figured the easiest way to prevent an accidental form submission by way of...
3
by: n3mtkj3mzsir0cy | last post by:
I have created web pages that do client-side form validation using the onclick directive. E.g., <form action=other_page.cgi method=post> Enter your age: <input name=age> <input type="submit"...
4
by: Rick | last post by:
Hello, I'm having trouble with submitting my form when checking to see if data is present in the user-inputted fields. What I want to happen is for the user to input various pieces of data,...
4
by: Wysiwyg | last post by:
I need to validate a form to ensure that all of the fields add up correctly. I can't do this while the user is entering data since validation needs to be done after the entry is completed. What's...
7
by: Jo Inferis | last post by:
For reasons that are unlikely to become clear at the moment, I have a page with some validation controls on it which opens a dialog. The dialog does *stuff* and then closes with a call to : ...
9
by: julie.siebel | last post by:
Hello all! As embarrassing as it is to admit this, I've been designing db driven websites using javascript and vbscript for about 6-7 years now, and I am *horrible* at form validation. To be...
18
by: Axel Dahmen | last post by:
Hi, trying to submit an ASPX form using the key (using IE6) the page is not submitted in my web project. Trying to debug the pages' JavaScript code I noticed that there's some ASP.NET client...
18
by: NavinM | last post by:
I have a couple of forms that are misbehaving in FireFox, but work fine in IE. when i do submit( with submit button) a javascript function validates all of the fields entered, and stops the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.