Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old May 5th, 2008, 04:23 AM
Authorized User
 
Join Date: May 2007
Location: Hyderabad, Andhra Pradesh, India.
Posts: 95
Thanks: 5
Thanked 0 Times in 0 Posts
Default 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

Reply With Quote
  #2 (permalink)  
Old May 5th, 2008, 05:01 AM
Friend of Wrox
 
Join Date: Oct 2004
Location: delhi, delhi, India.
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

Hi Abhishek!!,
On change of the textbox you can compare the entered value with the Current date .
hope this will help you

Cheers :)

vinod
Reply With Quote
  #3 (permalink)  
Old May 5th, 2008, 05:05 AM
Authorized User
 
Join Date: May 2007
Location: Hyderabad, Andhra Pradesh, India.
Posts: 95
Thanks: 5
Thanked 0 Times in 0 Posts
Default

Can u show me by code how to do it?



-- Abhishek

Reply With Quote
  #4 (permalink)  
Old May 5th, 2008, 06:29 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

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)
Reply With Quote
  #5 (permalink)  
Old May 5th, 2008, 06:44 AM
Authorized User
 
Join Date: May 2007
Location: Hyderabad, Andhra Pradesh, India.
Posts: 95
Thanks: 5
Thanked 0 Times in 0 Posts
Default

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

Reply With Quote
  #6 (permalink)  
Old May 5th, 2008, 07:00 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

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)
Reply With Quote
  #7 (permalink)  
Old May 5th, 2008, 05:47 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

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
Reply With Quote
  #8 (permalink)  
Old May 6th, 2008, 12:28 AM
Authorized User
 
Join Date: May 2007
Location: Hyderabad, Andhra Pradesh, India.
Posts: 95
Thanks: 5
Thanked 0 Times in 0 Posts
Default

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
Reply With Quote
  #9 (permalink)  
Old May 6th, 2008, 01:36 AM
Imar's Avatar
Wrox Author
Points: 71,164, Level: 100
Points: 71,164, Level: 100 Points: 71,164, Level: 100 Points: 71,164, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,948
Thanks: 79
Thanked 1,555 Times in 1,532 Posts
Default

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.
Reply With Quote
  #10 (permalink)  
Old May 6th, 2008, 02:41 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

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)
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
how can validate dynamic textbox field & get data alpi Classic ASP Basics 0 November 4th, 2007 02:24 PM
hi help me to write javascript to validate textbox karthikc85 XML 1 October 12th, 2006 03:12 AM
Validate two textbox one for area code and number debjanib ASP.NET 1.0 and 1.1 Professional 1 June 6th, 2006 01:00 PM
validate textbox stoneman Access 5 January 30th, 2004 10:49 AM



All times are GMT -4. The time now is 12:02 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.