Solved

javascript validation not working why?

Posted on 2007-11-20
3
331 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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 will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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…

744 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

17 Experts available now in Live!

Get 1:1 Help Now