473,327 Members | 1,896 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,327 software developers and data experts.

Validating Forms Input

Hi all,

I am looking for a little help validating a forms input. On the form are key
items which I do not wish to be zero length.
I have wrote the following function:

<script language=javascript>
function ValidateLength(oid, min, max)
{
var txt = document.getElementById(oid);
var length = txt.value.length;
if(length == 0)
{
alert("You must enter your reference, Company Name and Contact Name");
}
}
</script>

However their are still a few issues I would like to work out.

I all it with my forms sumbit event with the following:

<input type="submit" name="Submit" onclick="ValidateLength('txtRef',0,100)"
value="Submit Details">

However that will only check the length of the item txtRef, how can I check
more textbox values?
Also how can I stop the form posting if the alert is raised?

Thanks for any help you can provide
Mick
Jan 6 '06 #1
4 1165
Something like this will help
<form id="myform" onsubmit="validate()">
If your "validate" function returns false,form wont be submitted.

Jan 6 '06 #2
sunilp wrote on 06 jan 2006 in comp.lang.javascript:
Something like this will help
<form id="myform" onsubmit="validate()">
If your "validate" function returns false,form wont be submitted.


No, only in:

<form id="myform" onsubmit="return validate()">
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jan 6 '06 #3
"Evertjan." <ex**************@interxnl.net> wrote in
news:Xn********************@194.109.133.242:
sunilp wrote on 06 jan 2006 in comp.lang.javascript:
Something like this will help
<form id="myform" onsubmit="validate()">
If your "validate" function returns false,form wont be submitted.


No, only in:

<form id="myform" onsubmit="return validate()">


exactly. as long as your onsubmit has 'return' before your function,
then you can prevent the form from being submitted if you return false.

ie: in your validate() function:

if(length == 0)
{
alert("You must enter your reference, Company Name and Contact
Name");
return false;
}
else {
return true;
}

will submit your form if there are no 'errors', but stop submission if
there are.
Jan 6 '06 #4
Good Man wrote on 06 jan 2006 in comp.lang.javascript:
"Evertjan." <ex**************@interxnl.net> wrote in
news:Xn********************@194.109.133.242:
sunilp wrote on 06 jan 2006 in comp.lang.javascript:
Something like this will help
<form id="myform" onsubmit="validate()">
If your "validate" function returns false,form wont be submitted.
No, only in:

<form id="myform" onsubmit="return validate()">


exactly. as long as your onsubmit has 'return' before your function,
then you can prevent the form from being submitted if you return false.

ie: in your validate() function:

if(length == 0)
{
alert("You must enter your reference, Company Name and Contact
Name");
return false;
}
else {
return true;
}


Where I would call an else after a return superfluous
if(theLength == 0){
alert(".... mistake!");
return false;
}
return true;

will submit your form if there are no 'errors', but stop submission if
there are.


--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jan 6 '06 #5

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

Similar topics

5
by: The Plankmeister | last post by:
Hi... What's the best method of validating input characters? I would like to prevent users submitting exotic characters (such as those acquired on Windows Systems by pressing ALT+) and thought...
10
by: Samir | last post by:
Say I have 4 forms, all four have different numbers of text boxes. is there a script that I can use to check to make sure everything on the form is not blank?
6
by: sakms | last post by:
I am attempting to validate radio buttons in Netscape with JavaScript. Everything works excellent in Explorer, but refuses to work in Netscape (all versions). =========== JAVASCRIPT CODE...
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...
6
by: Advo | last post by:
Hi there. Having a few issues and cannot see a way to actually do the following. ive duplicated a simple questionnaire as shown here: http://www.hackeradio.com/questionnaire.html meaning...
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,...
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...
3
by: William Gill | last post by:
I have decided that Since I have to update the processing on many of my forms, I'm going to start them all over from scratch. Before I begin I thought I'd solicit comments on using the PHP regex...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.