Solved

javascript validation not working why?

Posted on 2007-11-20
3
335 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
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…

732 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