Solved

javascript validation not working why?

Posted on 2007-11-20
3
333 Views
Last Modified: 2009-07-29
why wont this work?? I want to make sure at least one feild is filled out.

<script>
function validate()
{
      if (document.form1.membno.value == "" || document.form1.lstnam.value == "" document.form1.lstnam.value == "");
                  {
                  alert('You must enter a member number!');
                  return false;
                  }
      else       
                  {
                  form.submit();
                  }
}

</script>
0
Comment
Question by:judsonmusic
  • 2
3 Comments
 
LVL 21

Expert Comment

by:nizsmo
ID: 20323390
you missed the second ||, here is the correct code:
<script>
function validate()
{
      if (document.form1.membno.value == "" || document.form1.lstnam.value == "" || document.form1.lstnam.value == "");
                  {
                  alert('You must enter a member number!');
                  return false;
                  }
      else       
                  {
                  form.submit();
                  }
}
 
</script>

Open in new window

0
 
LVL 3

Author Comment

by:judsonmusic
ID: 20323558
this sortof fixed it but now it is requiring that I fill all 3 feilds with something. I am only looking for one.

Is it the structure??
0
 
LVL 21

Accepted Solution

by:
nizsmo earned 500 total points
ID: 20323586
ahh i see, this should work then:
<script>
function validate()
{
      if (document.form1.membno.value == "" && document.form1.lstnam.value == "" && document.form1.lstnam.value == "");
                  {
                  alert('You must enter a member number!');
                  return false;
                  }
      else       
                  {
                  form.submit();
                  }
}
 
</script>

Open in new window

0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question