943,861 Members | Top Members by Rank

Ad:
Sep 25th, 2009
-1

validation help

Expand 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

JavaScript Syntax (Toggle Plain Text)
  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.
Similar Threads
puk
Reputation Points: 8
Solved Threads: 0
Light Poster
puk is offline Offline
25 posts
since May 2008
Sep 26th, 2009
0

Re: validation help

Click to Expand / Collapse  Quote originally posted by puk ...
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...
Reputation Points: 120
Solved Threads: 61
Posting Pro
Troy III is offline Offline
511 posts
since Jun 2008
Sep 26th, 2009
0

Re: validation help

Thanx a lot for your help. That has solved my problem. Thank you
puk
Reputation Points: 8
Solved Threads: 0
Light Poster
puk is offline Offline
25 posts
since May 2008
Sep 26th, 2009
0

Re: validation help

You're wellcome. Thanks for your feedback.
Reputation Points: 120
Solved Threads: 61
Posting Pro
Troy III is offline Offline
511 posts
since Jun 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: doubt with client side javascripting
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: help with two column dynamic table sum





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC