Solved

javascript validation not working why?

Posted on 2007-11-20
3
332 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
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…
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…

863 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now