View Full Version : multiplte OnSubmits in forms

12-18-2008, 06:15 PM
In my contact form I have JS Submit Once code that is activated by OnSubmit. I have been trying to add JS Validation to check if fields are empty before form is submitted, but it is also activated by OnSubmit.

How could I use both where the validation is checked first then it goes to the submit once.

I tried adding th validation code to the beginning of the submit once code. but it didnt work :(

edit: this might be in the wrong forum, I had 2 forums windows up and I wasnt looking when I clicked New Thread, please move to html forum if needed.

12-18-2008, 09:51 PM
Post what code you've got and we may be able to help you. (Disregard if this is already being answered in another forum.)

Typically your onsubmit looks something like this: onsubmit="return doSomething()" where doSomething is a function that returns true if the form is OK and false if not (returning false cancels the submission).

If you have a second function, doAnother, you can combine these so the form submits only if both functions return true: onsubmit="return doSomething() && doAnother()"

In this case if either doSomething() or doAnother() returns false the form will not submit.

12-19-2008, 07:04 AM
this is my empty field validation code:

<script language="JavaScript">
function validateFormOnSubmit(theForm) {
var reason = "";

reason += validateEmpty(theForm.from);

if (reason != "") {
alert("Some fields need correction:\n" + reason);
return false;

return true;

function validateEmpty(fld) {
var error = "";

if (fld.value.length == 0) {
fld.style.background = 'Yellow';
error = "The required field has not been filled in.\n"
} else {
fld.style.background = 'White';
return error;

this is my SubmitOnce code:

<script language="JavaScript">
//Submit Once form validation-
// Dynamic Drive (www.dynamicdrive.com (http://www.dynamicdrive.com))
//For full source code, usage terms, and 100's more DHTML scripts, visit http://dynamicdrive.com
//if IE 4+ or NS 6+
function submitonce(theform){
if (document.all||document.getElementById){
//screen thru every element in the form, and hunt down "submit" and "reset"
for (i=0;i<theform.length;i++){
var tempobj=theform.elements[i]
//disable em
var horizontal_offset="9px"
var vertical_offset="0"
var ie=document.all
var ns6=document.getElementById&&!document.all
function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
return totaloffset;
function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
function clearbrowseredge(obj, whichedge){
var edgeoffset=(whichedge=="rightedge")? parseInt(horizontal_offset)*-1 : parseInt(vertical_offset)*-1
if (whichedge=="rightedge"){
var windowedge=ie && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-30 : window.pageXOffset+window.innerWidth-40
if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
var windowedge=ie && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
return edgeoffset

your saying I can combine those in a OnSubmit tag? so the below would work?

<form onSubmit="return validateFormOnSubmit(this) && submitonce(this)">

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum