Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

javascript validation not working why?

Posted on 2007-11-20
3
Medium Priority
?
340 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 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
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…
Suggested Courses

916 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