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;}
  }
}
ShawnCplus commented: This isn't your first post, use code tags. Hell, there's even a code tag button -2

Recommended Answers

All 3 Replies

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...

Thanx a lot for your help. That has solved my problem. Thank you

You're wellcome. Thanks for your feedback.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.