[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Javascript || Syntax

Posted on 2005-05-03
6
Medium Priority
?
248 Views
Last Modified: 2010-04-17
I want a value to be either 0 or 13 digits this is what I have, but it doesn't work.  It returns False everytime

        if (document.Info.MarrsID.value.length != 13 || document.Info.MarrsID.value.length != 0)
        {
       alert("Please Enter a Valid MarrsID.");
        return false;
        }
0
Comment
Question by:mark951
4 Comments
 
LVL 53

Accepted Solution

by:
COBOLdinosaur earned 336 total points
ID: 13921863
One of those has to always be true becasue they are mutually exclusive you want AND, not OR

if (document.Info.MarrsID.value.length != 13 && document.Info.MarrsID.value.length != 0)
        {
       alert("Please Enter a Valid MarrsID.");
        return false;
        }


Cd&
0
 

Author Comment

by:mark951
ID: 13921930
But a value can not be 13 digits AND 0 Digits at the same time.
0
 
LVL 55

Assisted Solution

by:Jaime Olivares
Jaime Olivares earned 332 total points
ID: 13922029
CobolDinosaur is correct, but if the inverted logic makes more sense to you, you can try:

if ( ! (document.Info.MarrsID.value.length==13 || document.Info.MarrsID.value.length== 0) )
        {
       alert("Please Enter a Valid MarrsID.");
        return false;
        }

0
 
LVL 10

Assisted Solution

by:Andrew Beers
Andrew Beers earned 332 total points
ID: 13929569
Here's the reason mark951:

when you say
document.Info.MarrsID.value.length != 13 || document.Info.MarrsID.value.lenght != 0
You are essentially saying this
If MarrsID.value.length is not 13 or it is not 0 return false
So the logic states if I have 13 it still is NOT equal to zero and once again returns false.

The idea you want is if it is 0 or 13 I assume you want to return true so you need && instead of ||.

Then you would have if MarrsID.value.length is not 13 and it is not 0 then return false
So if you have 0 or 13 the program will take the else statement and return True.  (I would assume)


~Aqua
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
In this post we will learn different types of Android Layout and some basics of an Android App.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Introduction to Processes

867 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