2 similar input validations on one form

This is a discussion on "2 similar input validations on one form" within the JavaScript Forum section. This forum, and the thread "2 similar input validations on one form are both part of the Program Your Website category.



 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices


Reply
 
LinkBack Thread Tools
  #1  
Old Jan 25th, 2006, 09:04
New Member
Join Date: Jan 2006
Age: 24
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
2 similar input validations on one form

Hi, new guy here

I need to have two user input dates validated on a single form when the user clicks submit. At the moment I only hvae it validating one date and I'm not sure how to have it check the other, do I need some sort of a loop?

The form code is:

Code: Select all
<form name="startDateForm" method="post" action="pass.jsp" onSubmit="return ValidateForm()">

<input name="projectStartFromDate" type="text" id="projectStartFromDate">

<input name="projectStartToDate" type="text" id="projectStartToDate">
The Validation function is:

Code: Select all
function ValidateForm(){
    var dt=document.startDateForm.projectStartFromDate
    if(dt.value == '') return true;
    else if(isDate(dt.value)==false){
        dt.focus()
        return false
    }
    return true
 }
The isDate function called upon just defines the number of days in each month etc.

Thanks

EDIT:Link to doc if needed
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Jan 25th, 2006, 11:28
benbacardi's Avatar
Highly Reputable Member
Join Date: Feb 2004
Location: United Kingdom
Age: 20
Posts: 611
Thanks: 0
Thanked 0 Times in 0 Posts
Re: 2 similar input validations on one form

can you not just add a couple of lines to your code to make:

Code: Select all
function ValidateForm(){
    var dt=document.startDateForm.projectStartFromDate
    if(dt.value == '') return true;
    else if(isDate(dt.value)==false){
        dt.focus()
        return false
    }
    var dt2=document.startDateForm.projectStartToDate
    if(dt2.value == '') return true;
    else if(isDate(dt2.value)==false){
        dt2.focus()
        return false
    }
    return true
 }
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Jan 25th, 2006, 16:33
New Member
Join Date: Jan 2006
Age: 24
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: 2 similar input validations on one form

I've done some experimenting and that's one of the solutions I came up with; unfortunately although it validates the first date filed ok it still allows an invalid entry through on the second and passes the page.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Jan 30th, 2006, 21:27
New Member
Join Date: Jan 2006
Age: 48
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Re: 2 similar input validations on one form

How about:

Code: Select all
function ValidateForm(){ var dt=document.startDateForm.projectStartFromDate if(dt.value == '') ValidateDate2(); else if(isDate(dt.value)==false){ dt.focus() return false } function ValidateDate2(){ var dt2=document.startDateForm.projectStartToDate if(dt2.value == '') return true; else if(isDate(dt2.value)==false){ dt2.focus() return false } return true }


The above is sloppy and off the top of my head, but you get the idea.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
similar, input, validations, form

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Hiding / Showing form fields based on previous form input John Alexander Hopper PHP Forum 1 Mar 10th, 2008 11:30
help with form input gncreditcards Web Page Design 6 Jan 23rd, 2008 01:34
adding a field input to the subject in a form goatsalad PHP Forum 1 Feb 3rd, 2006 14:49
Anybody know how to change the color of a text input form in Physt Web Page Design 7 Aug 16th, 2004 08:44
<Input> to Requst.form() puzzle. Whitemirc Classic ASP 2 Nov 6th, 2003 09:27


All times are GMT. The time now is 00:07.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42