Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved

Join Date: May 2008
Posts: 22
Reputation: puk is an unknown quantity at this point 
Solved Threads: 0
puk puk is offline Offline
Newbie Poster

validation help

 
-1
  #1
Sep 25th, 2009
I have a text box in a form that is validated to accept a value called ds01 but i also want the textbox to be allowed to accept empty spaces that is if nothing is entered in the textbox. The problem is that it does not accept anything other than ds01. Thanx in advance for your help. This is my script

  1. function validate_choice(field,alerttxt)
  2. {
  3. with (field)
  4. {
  5. if (value != "ds01")
  6. {
  7. alert(alerttxt);return false;
  8. }
  9. else if (value ==null || value == "" || value=="ds01")
  10. {
  11. return true;
  12. }
  13. }
  14. }
  15.  
  16. function validate_form(thisform)
  17. {
  18. with (thisform)
  19. {
  20. if (validate_choice(webdev, "You Must Enter the Correct Code.Please Enter ds01!.Thank You!")==false)
  21. {webdev.focus();return false;}
  22. }
  23. }
Last edited by peter_budo; Sep 27th, 2009 at 8:27 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 348
Reputation: Troy III will become famous soon enough Troy III will become famous soon enough 
Solved Threads: 42
Troy III's Avatar
Troy III Troy III is offline Offline
Posting Whiz

Re: validation help

 
0
  #2
Sep 26th, 2009
Originally Posted by puk View Post
I have a text box in a form that is validated to accept a value called ds01 but i also want the textbox to be allowed to accept empty spaces that is if nothing is entered in the textbox. The problem is that it does not accept anything other than ds01. Thanx in advance for your help. This is my script

function validate_choice(field,alerttxt)
{
with (field)
{
if (value != "ds01")
{
alert(alerttxt);return false;
}
else if (value ==null || value == "" || value=="ds01")
{
return true;
}
}
}

function validate_form(thisform)
{
with (thisform)
{
if (validate_choice(webdev, "You Must Enter the Correct Code.Please Enter ds01!.Thank You!")==false)
{webdev.focus();return false;}
}
}
Here you go
function validate_choice(field,alerttxt){
with (field){
if (value ==null || value == "" || value=="ds01"){
    return true;
    }
else if (value != "ds01"){
    alert(alerttxt);
    return false;
    }
  }
}

*the part in red is not needed, but doesn't cause problems...
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 22
Reputation: puk is an unknown quantity at this point 
Solved Threads: 0
puk puk is offline Offline
Newbie Poster

Re: validation help

 
0
  #3
Sep 26th, 2009
Thanx a lot for your help. That has solved my problem. Thank you
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 348
Reputation: Troy III will become famous soon enough Troy III will become famous soon enough 
Solved Threads: 42
Troy III's Avatar
Troy III Troy III is offline Offline
Posting Whiz

Re: validation help

 
0
  #4
Sep 26th, 2009
You're wellcome. Thanks for your feedback.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC