473,407 Members | 2,306 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,407 software developers and data experts.

Before Form Submit?

Hello

I am using the following line of code at the very end of my html file to
run a javascript function before a form is submitted.

document.forms[0].onsubmit = chkUsername;

It works for one method, but what do I do when I want to call 2 methods? I
tried this:

document.forms[0].onsubmit = chkUsername;
document.forms[0].onsubmit = chkUsername2;

but the last one is the only one that is run. It seems overwrite the first
one.

Does anyone have any suggestions?

Thanks
Jul 20 '05 #1
5 5738
On Tue, 24 Feb 2004 23:52:31 GMT, Brett Baisley
<ba*****@hotmail.com.REMOVETHIS> wrote:
I am using the following line of code at the very end of my html file to
run a javascript function before a form is submitted.

document.forms[0].onsubmit = chkUsername;

It works for one method, but what do I do when I want to call 2 methods?
I tried this:

document.forms[0].onsubmit = chkUsername;
document.forms[0].onsubmit = chkUsername2;

but the last one is the only one that is run. It seems overwrite the
first one.
It does.
Does anyone have any suggestions?


document.forms[ 0 ].onsubmit = function() {
chkUsername();
chkUsername2();
}

or

document.forms[ 0 ].onsubmit = validateForm;

where validateForm is a function that calls chkUsername() followed by
chkUsername2().

Hope that helps,
Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #2
Ok, thanks. But if either of the functions the main one class return false,
will it stop?
"Michael Winter" <M.******@blueyonder.co.invalid> wrote in message
news:op**************@news-text.blueyonder.co.uk...
On Tue, 24 Feb 2004 23:52:31 GMT, Brett Baisley
<ba*****@hotmail.com.REMOVETHIS> wrote:
I am using the following line of code at the very end of my html file to
run a javascript function before a form is submitted.

document.forms[0].onsubmit = chkUsername;

It works for one method, but what do I do when I want to call 2 methods?
I tried this:

document.forms[0].onsubmit = chkUsername;
document.forms[0].onsubmit = chkUsername2;

but the last one is the only one that is run. It seems overwrite the
first one.


It does.
Does anyone have any suggestions?


document.forms[ 0 ].onsubmit = function() {
chkUsername();
chkUsername2();
}

or

document.forms[ 0 ].onsubmit = validateForm;

where validateForm is a function that calls chkUsername() followed by
chkUsername2().

Hope that helps,
Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)

Jul 20 '05 #3
On Wed, 25 Feb 2004 22:24:16 GMT, Brett Baisley
<ba*****@hotmail.com.REMOVETHIS> wrote:

[snipped top-post]
Ok, thanks. But if either of the functions the main one class return
false, will it stop?


Yes. Take this modified version of an example in my last post:

document.forms[ 0 ].onsubmit = function() {
if( !chkUsername() ) return false;
return chkUsername2();
}

If chkUsername() returns false, the event handler will exit, return false,
and cancel the submission. If it returns true, execution will continue
with the call the chkUsername2(). Whatever the return value from that
function, it will be return it as the function exits. If the value
evaluates to false, the submission will be cancelled.

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #4
Michael Winter wrote:
On Wed, 25 Feb 2004 22:24:16 GMT, Brett Baisley
<ba*****@hotmail.com.REMOVETHIS> wrote:

[snipped top-post]
Ok, thanks. But if either of the functions the main one class return
false, will it stop?


Yes. Take this modified version of an example in my last post:

document.forms[ 0 ].onsubmit = function() {
if( !chkUsername() ) return false;
return chkUsername2();
}


Unless I'm missing something, what you wrote above could be replaced with:

document.forms[ 0 ].onsubmit = function() {
return chkUsername() && chkUsername2();
}

--
| Grant Wagner <gw*****@agricoreunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html
Jul 20 '05 #5
On Fri, 27 Feb 2004 17:38:17 GMT, Grant Wagner
<gw*****@agricoreunited.com> wrote:
Michael Winter wrote:
[snip]
document.forms[ 0 ].onsubmit = function() {
if( !chkUsername() ) return false;
return chkUsername2();
}


Unless I'm missing something, [...]


Nope.
what you wrote above could be replaced with:
I knew there had to be a way to make it smaller (mine seemed unnecessarily
bulky), and your suggestion is that way.
document.forms[ 0 ].onsubmit = function() {
return chkUsername() && chkUsername2();
}


Thank you. :)

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: luc wastiaux | last post by:
Hello, I am writing an application to handle support requests, and the user needs to have his request number printed out in front of him even before he hits the "submit" button. I have no idea how...
14
by: Kenneth Keeley | last post by:
Hi How can I run a java script function before a form is submited back to the server. What I wish to do is have a upload form that when a user clicks the submit button a javascript function opens...
4
by: Mark Miller | last post by:
I've been trying to execute a javascript function just before submit on a form that contains an <input type="file"> input field and it isn't working. The reason I want to do this is the end users...
2
by: Syam | last post by:
Hello everyone, I am just barely two months old into learning asp.net and vb.net. Currently I am working on a project to store customer database. I have a question about creating a preview page:...
4
by: Benny Ng | last post by:
Dear All, <input type="checkbox" name="chkAgreement" value="0">I agree with the above terms and conditions <asp:ImageButton ID="ImgBtnSubmit" Runat="server" CausesValidation=True...
7
by: Schmidty | last post by:
Okay...I have another 'newbie' question; I have a function that loads a page and the action is $_SERVER; In the form that is in a function(method?) within a class a variable is passed back to...
4
by: plumba | last post by:
Let me explain.... I have a form (most of which you guys have helped me with!!). The initial problem I was having is that it was holding the data in the fields after submit, I resolved this by...
10
by: pt36 | last post by:
Hi I have a page with a form and a textbox. before to submit the form I want to chek if the inserted value in the textbox is already present in a database. So I need to pass the textbox value...
5
by: Rider | last post by:
Hi All, Here is the reason why i ak asking for ur help. I have a edit form in which the values already stored in DB are populated. User can edit some or all the values in the form. then he...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.