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

x
Solved

# Javascript || Syntax

Posted on 2005-05-03
Medium Priority
248 Views
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)
{
return false;
}
0
Question by:mark951

LVL 53

Accepted Solution

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)
{
return false;
}

Cd&
0

Author Comment

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

LVL 55

Assisted Solution

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) )
{
return false;
}

0

LVL 10

Assisted Solution

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

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
###### Suggested Courses
Course of the Month20 days, 10 hours left to enroll