473,473 Members | 1,955 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

validating two forms

I have put two snips of code I use in the body section of my page to
validate and submit two forms.

The first snip worked fine until I included the second...is the
problem the fact variables have the same name?

Cheers,

Chris

<script type="text/javascript">
var field1 = new LiveValidation( 'field1', {onlyOnSubmit: true } );
field1.add( Validate.Presence );

var mySelect1 = new LiveValidation('mySelect1');
mySelect1.add(Validate.Exclusion, { within: ['Please select...'],
failureMessage: "x"});

var automaticOnSubmit = field1.form.onsubmit;
field1.form.onsubmit = function(){
var valid = automaticOnSubmit();
...........
}
</script>
------------------------------------------------
<script type="text/javascript">
var field2 = new LiveValidation( 'field2', {onlyOnSubmit: true } );
field2.add( Validate.Presence );

var mySelect2 = new LiveValidation('mySelect2');
mySelect2.add(Validate.Exclusion, { within: ['Please select...'],
failureMessage: "x"});

var automaticOnSubmit = field1.form.onsubmit;
field2.form.onsubmit = function(){
var valid = automaticOnSubmit();
.............
}
</script>
Sep 20 '08 #1
1 2019
SAM
Chris a écrit :
I have put two snips of code I use in the body section of my page to
validate and submit two forms.
That smells prototype.js or something like that, no ?

An handmade JS script to validate a form is not so difficult to do.

function validate(f) {
f = f.elements, n = f.length;
for(var i=0; i<n; i++) {
if(f[i].type == 'radio') {
var r = f[f[i].name], z = r.length, ok = false;
for(var j=0; j<z; j++) if(r[j].checked) ok = true;
i += j;
if(!ok) {
alert('Choice something in : '+f[i].name);
r[0].focus();
return false;
}
}
if((f[i].type == 'text' || f[i].tagName == 'textarea') &&
f[i].value.length <1) {
alert('Complete field : '+f[i].name);
f[i].focus();
return false;
}
if(f[i].tagName == 'select') {
var k = f[i].selectedIndex;
if(k==0) {
alert('Forgiven the choice : '+f[i].options[0].text);
f[i].focus();
return false;
}
}
}
return true;
}
window.onload = function() {
document.forms[0].onsubmit = function(){ return validate(this); };
document.forms[1].onsubmit = function(){ return validate(this); };
}
The first snip worked fine until I included the second...is the
problem the fact variables have the same name?
Probably ?
--
sm
Sep 20 '08 #2

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

Similar topics

2
by: Will | last post by:
I have been having problems validating an XForms document against the XForms schema located at http://www.w3.org/MarkUp/Forms/2002/XForms-Schema.xsd. I have reduced the XForm to its bare bones...
2
by: Chris Dunaway | last post by:
I have a form with a textbox and numerous panels, buttons and other controls. I have handled the textbox Validating and Validated events. The textbox will hold a filename. In the validating...
0
by: Matthew | last post by:
All, I have searched google and the newsgroups but can't find anything the same as what I am experiencing (though I may have missed something). I have controls (textboxes) within UserControls...
0
by: Gary Shell | last post by:
I am experiencing some strange behavior between a UserControl's validating event and a treeview control. Initially, I thought it was related to an issue in the Knowledgebase article 810852...
4
by: easoftware | last post by:
I am using VS .Net 2003 and VB. I have an app with one parent and two Mdi child forms. I need to validate data in the Mdi form. The Form.Validating event works when I try to close a Mdi form,...
16
by: Al Santino | last post by:
Hi, It appears displaying a messagebox in a validating event will cancel the subsequent event. In the program below, button 2's click event doesn't fire if you open a dialog box in button 1's...
5
by: ameen.abdullah | last post by:
Hi Guys, I have a textbox in windows form that should only accept alphabets, numbers, spaces and underscore. If the textbox contains anyother character it should display a msg at the time of...
16
by: shyamg | last post by:
Hi, this is my javascript validating the fields in mozilla FF but its working and validating only one field. how to write the and how to works the script .................. function...
1
by: mehdi | last post by:
Hi, Consider a dialog that contains some control. You know, the form is validated when every single control in the form is validated successfully. However, if one control tries to cancel the...
1
by: =?Utf-8?B?bGpsZXZlbmQy?= | last post by:
I've noticed that controls do not raise a Validating event if they are contained in a ToolStripDropDown via a ToolStripControlHost item. Please run the following sample and follow the instructions...
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
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...
1
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.