How could I add a colored red message at the bottom of my textbox saying that this field is required. I know how to validate with javascript, but how could I place a message at the bottom of a particular textbox wherein the bottom is empty at first? A tutorial
with sample would be great.
Thanks. I do understand now and working with it using Javascript without jquery.
I have three textboxes. I can show error messages but only to a single element. I wish to display all the errors at once when the form is submitted. How could I accomplish this? I'm using an if statement validations.
if (textbox1 is error)
{
//show error
}
if(textbox2 is error)
{
//show error
}
Because of this, errors are displaying one by one.
I'm using javascript for my client validation and I would like this to work the way I wanted to. I have three textboxes for last name, middle name and firstname. All the fields are mandatory and if the form is submitted there would be an error to display
below the textbox. The problem now is I couldn't show three errors at once. I could only show one error at a time. The error msgs are specific that is "Last name required", "First name required
Here's my JS structure
function validate() {
if (textbox1 == empty) { //show error below textbox by using getElementById to the empty div below it }
if (textbox2 == empty) { //show error }
if (textbox3 == empty) { //show error }
As you can see I'm using an if statement which only runs a block of code once regardless if the others is true. Now, how to show multiple errors at once?
As you can see I'm using an if statement which only runs a block of code once regardless if the others is true. Now, how to show multiple errors at once?
That's probably because you're using return statements within the individual if blocks. Could you post the entire code within the validate function?
AngelicOne
Member
220 Points
278 Posts
Javascript message validation
Jul 30, 2011 07:46 AM|LINK
How could I add a colored red message at the bottom of my textbox saying that this field is required. I know how to validate with javascript, but how could I place a message at the bottom of a particular textbox wherein the bottom is empty at first? A tutorial with sample would be great.
Raigad
Contributor
5129 Points
956 Posts
Re: Javascript message validation
Jul 30, 2011 08:00 AM|LINK
function Check()
{
var text= document.getElementById("<%=txtHadbast.ClientID%>").value;
if(text=="")
{
document.getElementById("dvError").InnerHTML="Please enter text"
return false;
}
return true;
}
In html
<asp:TextBox ID="txtHadbast" runat="server" Width="144px"></asp:TextBox>
<div id='dvError' style="color:Red;"></div>
<asp:Button ID="btnSearch" runat="server" OnClientClick="return Check();" Width="80px" Text="Search"></asp:Button>
Mark as Answer, if the post helped you...
Visit My Blog
bhavik.y.sha...
Participant
1610 Points
449 Posts
Re: Javascript message validation
Jul 30, 2011 08:15 AM|LINK
Hello,
Please go thru below link which shows jQuery validation with source code.
http://docs.jquery.com/Plugins/validation
http://speckyboy.com/2009/12/17/10-useful-jquery-form-validation-techniques-and-tutorials-2/
Thanks & Regards.
Skype ID : bhavik.shah2004
AngelicOne
Member
220 Points
278 Posts
Re: Javascript message validation
Jul 30, 2011 10:31 AM|LINK
Thanks. I do understand now and working with it using Javascript without jquery.
I have three textboxes. I can show error messages but only to a single element. I wish to display all the errors at once when the form is submitted. How could I accomplish this? I'm using an if statement validations.
if (textbox1 is error)
{
//show error
}
if(textbox2 is error)
{
//show error
}
Because of this, errors are displaying one by one.
Raigad
Contributor
5129 Points
956 Posts
Re: Javascript message validation
Jul 30, 2011 11:45 AM|LINK
Hi use requiredfield validator for this it would be best for you
do like this
for each textbox you required one requiredfiledvalidator
<asp:TextBox ID="txtBox" runat="server" Width="144px"></asp:TextBox>
<asp:RequiredFieldValidator ID="txtKhewatRequiredFieldValidator" ControlToValidate="txtBox"
ValidationGroup="grp1" Text="*" ErrorMessage="please enter text" runat="server" />
<asp:Button ID="btnView" ValidationGroup="grp1" runat="server" Width="80px" Text="View"></asp:Button>
<asp:ValidationSummary ID="valSumView" Style="text-align: left; margin-left: 593px;" DisplayMode="BulletList"
HeaderText="You must enter a value in the following fields:"runat="server" ValidationGroup="grp1" />
Mark as Answer, if the post helped you...
Visit My Blog
AngelicOne
Member
220 Points
278 Posts
Re: Javascript message validation
Jul 31, 2011 06:01 AM|LINK
I'm not using ASP.net. I'm trying to do it using HTML, CSS and JavaScript only for training.
Here's my site http://localhost/webpage/AliceEnrollment.php.
Try to submit the form and you'll notice that the message shows one by one.
AngelicOne
Member
220 Points
278 Posts
Re: Javascript message validation
Jul 31, 2011 06:27 AM|LINK
I'll elaborate my problem.
I'm using javascript for my client validation and I would like this to work the way I wanted to. I have three textboxes for last name, middle name and firstname. All the fields are mandatory and if the form is submitted there would be an error to display below the textbox. The problem now is I couldn't show three errors at once. I could only show one error at a time. The error msgs are specific that is "Last name required", "First name required
Here's my JS structure
function validate()
{
if (textbox1 == empty)
{
//show error below textbox by using getElementById to the empty div below it
}
if (textbox2 == empty)
{
//show error
}
if (textbox3 == empty)
{
//show error
}
As you can see I'm using an if statement which only runs a block of code once regardless if the others is true. Now, how to show multiple errors at once?
Abhishek Bha...
Contributor
2222 Points
436 Posts
Re: Javascript message validation
Jul 31, 2011 07:07 AM|LINK
I couldn't. You'll have to post the url that has the explicit IP.
Abhishek Bha...
Contributor
2222 Points
436 Posts
Re: Javascript message validation
Jul 31, 2011 07:10 AM|LINK
That's probably because you're using return statements within the individual if blocks. Could you post the entire code within the validate function?
AngelicOne
Member
220 Points
278 Posts
Re: Javascript message validation
Jul 31, 2011 07:45 AM|LINK
I'm terribly sorry for putting an invalid url. here it is http://angelickp.byethost24.com/AliceEnrollment.php