473,513 Members | 7,598 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Basic validation question

1 New Member
Hi all, I have a text area that can contain no less than 130 characters. The javascript validation I have is as follows:

[HTML]<script type="text/javascript">
function validate(field)
{
var chars = document.getElementById(field).value;
if (chars.length < 130)
{
alert("The news story content must be a minimum of 130 characters to properly display. Please enter more content and re-submit the form.");
return false;
}
else
{
return true;
}
}
</script>[/HTML]

The HTML in the form reads:
[HTML]<form action="datainsert.php?type=news" method="post" name="addNews" onsubmit="return validate(content)">[/HTML]

When I test the form with less than 130 characters in the textarea, I get the warning, but it continues on and posts data from the form. How can I stop the form from posting and returning the user to correct the error?

Thanks, C
Jul 27 '08 #1
1 912
RamananKalirajan
608 Contributor
Hai Dude, I hope this code will help you out. Just try this.

[HTML]</html>
<head>
<script type="text/javascript">
function validate()
{
var chars = document.getElementById('field').value;
if (chars.length < 130)
{
alert("The news story content must be a minimum of 130 characters to properly display. Please enter more content and re-submit the form.");
return false;
}
else
{
return true;
}
}
</script>
</head>
<form action="demo.html" method="post" onSubmit="return validate()">
<textarea id="field">
</textarea>
<input type="submit" value="Submit Me">
</form>
</html>[/HTML]

The problem in your code is in document.getElementById() you hevent place the field within quotes.

Regards
Ramanan Kalirajan
Jul 28 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2132
by: wumingshi | last post by:
Hi, When validating an XML instance, sometimes the schema is not enough to expression the validation rules. Additional validation rules may be expressed in an application-specific way. For...
9
2327
by: rbronson1976 | last post by:
Hello all, I have a very strange situation -- I have a page that validates (using http://validator.w3.org/) as "XHTML 1.0 Strict" just fine. This page uses this DOCTYPE: <!DOCTYPE html PUBLIC...
6
1107
by: Bliss | last post by:
ok I am rather new to the .net framework. I come from a J2EE background. I am not a java snob though =-) I happen to like both platforms. At any rate I came accross a simple problem that I was...
8
1195
by: Grant Merwitz | last post by:
hi I am using Javascript to do my validation This is so i can display a loading message after a form is submitted. Now, currently i do so like this. I have a button, textbox and label like...
27
35894
by: code_wrong | last post by:
Visual Basic (not dot net) what is the best way to check the User has entered an integer into an InputBox? isNumeric() checks for a numeric value .. but does not notify of numbers with decimal...
9
4153
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...
7
1194
by: CSharpguy | last post by:
I'm coding my first business web app in .NET 2.0 and its only a read only web app. I'm just pulling data from the database and allowing users to filter the data in the grids by using dropdowns....
27
4681
by: Chris | last post by:
Hi, I have a form for uploading documents and inserting the data into a mysql db. I would like to validate the form. I have tried a couple of Javascript form validation functions, but it...
4
1217
by: Tony Johansson | last post by:
Hello! I know this might not be the appropriate forum for xml question. But xml is so important for .NET I hope my basic question can be answered in this forum. I just wonder does every xml...
0
7254
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
7153
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
5677
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5079
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
4743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3230
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3218
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1585
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
796
muto222
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.