473,587 Members | 2,320 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.getEle mentById(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="datains ert.php?type=ne ws" method="post" name="addNews" onsubmit="retur n validate(conten t)">[/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 915
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.getEle mentById('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.ht ml" method="post" onSubmit="retur n validate()">
<textarea id="field">
</textarea>
<input type="submit" value="Submit Me">
</form>
</html>[/HTML]

The problem in your code is in document.getEle mentById() 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
2140
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 example, using XPath or Java method. So is there a concept and/or standard for post-schema validation or application validation? Is there any hook in XML...
9
2331
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 "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> When I change the DOCTYPE to (what should be the...
6
1111
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 left unsure how to handle. I need 2 forms on a aspx page. I know that this has been addressed in length before however it seems to me that with all...
8
1199
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 so: <asp:textbox id="tb" runat="server"/>
27
35918
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 places inputBox returns a string so I could check for decimal point??? this seems like overkill The value returned can be asigned into an Integer...
9
4161
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 honest I usually hire someone to do it for me, grab predone scripts and kind of hack out the parts that I need, or just do very minimal validation...
7
1198
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. I've been reading and seen how you can drag and drop the controls and bind them that way, though I'm used to coding using a business layer and...
27
4716
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 appears that the data goes straight to the processing page, rather than the javascript seeing if data is missing and popping up an alert. I thought it...
4
1224
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 document have a XSD schema or XDR schema ? Is it possible to say that the purpose for schema is to have a definition for syntax.
0
7843
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8206
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8340
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7967
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8220
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5713
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5392
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3840
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2353
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 we have to send another system

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.