 |
| Javascript General Javascript discussions. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

May 5th, 2008, 04:23 AM
|
|
Authorized User
|
|
Join Date: May 2007
Posts: 95
Thanks: 5
Thanked 0 Times in 0 Posts
|
|
Javascript to validate a textbox
Hi All
I m making a web app using C#,ASP.NET 2.0. In my application, i have a textbox namely textbox1. From the GUI i m entering date in textbox1 in DD/MM/YYYY format. I have to validate the date entered in textbox that it "should not be greater than or equal to current date".
How to do this?
-- Abhishek
|
|

May 5th, 2008, 05:01 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2004
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Hi Abhishek!!,
On change of the textbox you can compare the entered value with the Current date .
hope this will help you
Cheers :)
vinod
|
|

May 5th, 2008, 05:05 AM
|
|
Authorized User
|
|
Join Date: May 2007
Posts: 95
Thanks: 5
Thanked 0 Times in 0 Posts
|
|
Can u show me by code how to do it?
-- Abhishek
|
|

May 5th, 2008, 06:29 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
You can use a compare validator, set the type to date. Make sure the culture is set correctly in your web.config and set CultureInvariantValues to false. Set the ValueToCompare server-side to the current date.
http://msdn.microsoft.com/en-us/libr...r_members.aspx
--
Joe ( Microsoft MVP - XML)
|
|

May 5th, 2008, 06:44 AM
|
|
Authorized User
|
|
Join Date: May 2007
Posts: 95
Thanks: 5
Thanked 0 Times in 0 Posts
|
|
Hi Joe
I dont want to do any server side validation, i want to handle client side only, thats why i have posted my issue in the javascript forum.
Can u show me by code how can i handle it in Javascript.
-- Abhishek
|
|

May 5th, 2008, 07:00 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
Well you claimed you were using asp.net. The solution I gave will do client-side validation provided that you don't set EnableClientScript to false.
(You still need to check server-side, anyone can defeat client-side validation either knowingly or unwittingly.)
--
Joe ( Microsoft MVP - XML)
|
|

May 5th, 2008, 05:47 PM
|
|
Friend of Wrox
|
|
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
|
|
my 2cents if I may - Why let the user enter a date, I always use a date picker pop up like most web sites do. users are used to this, date formats arnt an issue......to many things in the pro's list to go against IMO
Wind is your friend
Matt
www.elitemarquees.com.au
|
|

May 6th, 2008, 12:28 AM
|
|
Authorized User
|
|
Join Date: May 2007
Posts: 95
Thanks: 5
Thanked 0 Times in 0 Posts
|
|
Hi Matt
Well, i am using AJAX for date. It looks like people out here are not giving me a precise answer. My problem is that when an user selects date and press submit,the date chosen by the user should get validated client side. The date should not be equal or greater than the current date. Date being selected by the user is in DD/MM/YYYY format. I am trying hard to get this thing working using javascript. The validation should not be done by using ASP controls.
-- Abhishek
C# Programmer
|
|

May 6th, 2008, 01:36 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Not a precise answer?? I think Joe gave you one.
Maybe you don't understand how the validation controls work? Although they run at the server, they can emit client side script that fires at the *client*. So, simply use a CompareValidator control, set the current date as the value on the server (which is then transmitted to the client) and let the validation framework handle the rest.
Simple, clean and elegant and fully client side.
I don't see the problem, and I don't see why this wouldn't be precise. What's up with that requirement that "validation should not be done by using ASP controls"? Why not? They are designed specifically for these kind of scenarios.
Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
|
|

May 6th, 2008, 02:41 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
My current approach is to use a standard textbox, a claendar extender from the Ajax Control Toolkit, a required field validator if necessary, and a compare validator. The reason for that is that the extender still allows manual insertion of text into the box. I don't see the point of writing separate client-side validation, if I am using the ASP.NET model then I try to stick with that model even to the extent of inserting client-side code using the ClientScriptManager instead of directly including JavaScript.
--
Joe ( Microsoft MVP - XML)
|
|
 |