473,399 Members | 3,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

If statement to long for one line, goes to next line

200 100+
Good day, i have an If statement that is to long for one line goes to the second line.

I cant defein var for it as when the object are not there it gives an error.

So i had to go with the object value, I cant break it up more as it is a group of OR statements

How do i let the if continue on next line? please help

Expand|Select|Wrap|Line Numbers
  1.  else if((document.getElementById('VE1020User').value=="LOCAL" || document.getElementById('VE1020User').value=="NATIONAL") && document.getElementById('VE1060NewSupplier').value=="Yes" && document.getElementById('VE10IntVendorFields').value=="True")
  2.  {
  3.    if (document.getElementById('VE1080Name').value=="" || document.getElementById('VE10435SuppName').value=="" || document.getElementById('VE1090Postal').value=="" || document.getElementById('VE10445PostalCode').value=="" || document.getElementById('VE1010Province').value=="" || document.getElementById('VE10110Country').value=="" || document.getElementById('VE10120Phone').value=="" || document.getElementById('VE10130Fax').value=="" || document.getElementById('VE10140Email').value=="" || document.getElementById('VE10160Company').value=="" || document.getElementById('VE10170VendorType').value=="" || document.getElementById('VE10180Currency').value=="" || document.getElementById('VE10190Terms').value=="" || document.getElementById('VE10200PaymentType').value=="" || document.getElementById('VE10210Bank').value=="" || document.getElementById('VE10220BankCode').value=="" || document.getElementById('VE10230BankAccNo').value=="" || document.getElementById('VE10280SupplierAdd').value=="" || document.getElementById('V10290PhoneNumber').value=="" || document.getElementById('VE10310FaxNumber').value=="" || document.getElementById('VE10665TaxCode').value=="")
  4.  {
  5.  
Jan 20 '10 #1

✓ answered by gits

after having a look at the code first i would suggest to write a short helper method to shorten the code:
Expand|Select|Wrap|Line Numbers
  1. var getElVal = function(id) {
  2.     return document.getElementById(id).value;
  3. }
so you might use it like (and don't need to retype document.getElementById().value that much):
Expand|Select|Wrap|Line Numbers
  1. if ( (getElVal('VE1020User') == "LOCAL" 
  2.     || getElVal('VE1020User') == "NATIONAL") 
  3.     && getElVal('VE1060NewSupplier') == "Yes" 
  4.     && getElVal('VE10IntVendorFields') == "True" ) {
  5.  
  6.     // do something here
  7. }
basicly a condition don't need to be one line ... it is opened and terminated with corresponding brackets, so you could simply linebreak it. for readabilty it is best to have the conditions well seperated per line.

kind regards

6 17852
What do you mean "too long for one line"? There is no max. limit on how long a line can be. Likely that your text editor, or whatever you're using, is simply "wrapping" the IF line when it gets too long - but your code should still work normally. You can use an unlimited number of OR statements.

If you want, open your file in notepad (or whatever your os has) and that should display your IF statement without the new line. If it doesn't, delete the new line. Just to reiterate - lines can be as long as you like them. I'm sure I've written longer lines of javascript! (-;
Jan 20 '10 #2
ismailc
200 100+
Hi, Thank You for the assisting.
I was opening it notepad (js file) but to check if was correct i double click the js file & it would complain about the If line
because it breaks oof to the next line.

I done this to get me going for the time being:
Expand|Select|Wrap|Line Numbers
  1.  else if((document.getElementById('VE1020User').value=="LOCAL" || document.getElementById('VE1020User').value=="NATIONAL") && document.getElementById('VE1060NewSupplier').value=="Yes" && document.getElementById('VE10IntVendorFields').value=="True")
  2.  {
  3.       VE1080Name = document.getElementById('VE1080Name').value;
  4.       VE10435SuppName = document.getElementById('VE10435SuppName').value;
  5.       VE1090Postal=document.getElementById('VE1090Postal').value;
  6.       VE10445PostalCode=document.getElementById('VE10445PostalCode').value;
  7.       VE1010Province=document.getElementById('VE1010Province').value;
  8.       VE10110Country=document.getElementById('VE10110Country').value;
  9.       VE10120Phone=document.getElementById('VE10120Phone').value;
  10.       VE10130Fax=document.getElementById('VE10130Fax').value;
  11.       VE10140Email=document.getElementById('VE10140Email').value;
  12.       VE10160Company=document.getElementById('VE10160Company').value;
  13.       VE10170VendorType=document.getElementById('VE10170VendorType').value;
  14.       VE10180Currency=document.getElementById('VE10180Currency').value;
  15.       VE10190Terms=document.getElementById('VE10190Terms').value;
  16.       VE10200PaymentType=document.getElementById('VE10200PaymentType').value;
  17.       VE10210Bank=document.getElementById('VE10210Bank').value;
  18.       VE10220BankCode=document.getElementById('VE10220BankCode').value;
  19.       VE10230BankAccNo=document.getElementById('VE10230BankAccNo').value;
  20.       VE10280SupplierAdd=document.getElementById('VE10280SupplierAdd').value;
  21.       V10290PhoneNumber=document.getElementById('V10290PhoneNumber').value;
  22.       VE10310FaxNumber=document.getElementById('VE10310FaxNumber').value;
  23.       VE10665TaxCode=document.getElementById('VE10665TaxCode').value;
  24.  
  25.       if (VE1080Name==""  || VE10435SuppName=="" || VE1090Postal=="" || VE10445PostalCode=="" || VE1010Province==""|| VE10110Country=="" || VE10120Phone=="" || VE10130Fax=="" || VE10140Email=="" || VE10160Company=="" || VE10170VendorType=="" || VE10180Currency=="" || VE10190Terms=="" || VE10200PaymentType=="" || VE10210Bank=="" || VE10220BankCode=="" || VE10230BankAccNo=="" || VE10280SupplierAdd=="" || V10290PhoneNumber=="" || VE10310FaxNumber=="" || VE10665TaxCode=="")
  26.       {
  27.          showDialog('Warning','All Information is required (INTERNAL - Vendor Application Form).','warning');                    
  28.       }       
  29.  
  30.  
Jan 20 '10 #3
What exactly was the error you were getting? A "line is too long" error, surely not!?
Jan 20 '10 #4
ismailc
200 100+
The if would break to next line

If ... test
="" || test2="")

Error: At line: 50
Expected ")"

Regards
Jan 20 '10 #5
gits
5,390 Expert Mod 4TB
after having a look at the code first i would suggest to write a short helper method to shorten the code:
Expand|Select|Wrap|Line Numbers
  1. var getElVal = function(id) {
  2.     return document.getElementById(id).value;
  3. }
so you might use it like (and don't need to retype document.getElementById().value that much):
Expand|Select|Wrap|Line Numbers
  1. if ( (getElVal('VE1020User') == "LOCAL" 
  2.     || getElVal('VE1020User') == "NATIONAL") 
  3.     && getElVal('VE1060NewSupplier') == "Yes" 
  4.     && getElVal('VE10IntVendorFields') == "True" ) {
  5.  
  6.     // do something here
  7. }
basicly a condition don't need to be one line ... it is opened and terminated with corresponding brackets, so you could simply linebreak it. for readabilty it is best to have the conditions well seperated per line.

kind regards
Jan 20 '10 #6
ismailc
200 100+
Silly me - Thank You works great
Expand|Select|Wrap|Line Numbers
  1.  else if((document.getElementById('VE1020User').value=="LOCAL" || document.getElementById('VE1020User').value=="NATIONAL") && document.getElementById('VE1060NewSupplier').value=="Yes" && document.getElementById('VE10IntVendorFields').value=="True"
  2.           && document.getElementById('VE1080Name').value==""  || document.getElementById('VE10435SuppName').value=="" || document.getElementById('VE1090Postal').value=="" 
  3.           || document.getElementById('VE10445PostalCode').value=="" || document.getElementById('VE1010Province').value=="" || document.getElementById('VE10110Country').value=="" 
  4.           || document.getElementById('VE10120Phone').value=="" || document.getElementById('VE10130Fax').value=="" || document.getElementById('VE10140Email').value=="" 
  5.           || document.getElementById('VE10160Company').value=="" || document.getElementById('VE10170VendorType').value=="" || document.getElementById('VE10180Currency').value=="" 
  6.           || document.getElementById('VE10190Terms').value=="" || document.getElementById('VE10200PaymentType').value=="" || document.getElementById('VE10210Bank').value==""
  7.           || document.getElementById('VE10220BankCode').value=="" || document.getElementById('VE10230BankAccNo').value=="" || document.getElementById('VE10280SupplierAdd').value=="" 
  8.           || document.getElementById('V10290PhoneNumber').value=="" || document.getElementById('VE10310FaxNumber').value=="" || document.getElementById('VE10665TaxCode').value=="")
  9.  {
  10.        showDialog();                    
  11.  } 
  12.  
Jan 20 '10 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Benjamin | last post by:
Hello, I need some advice on a financial application I'm doing. First, I suppose I should give a little background so you know where I'm coming from. For 5 years I earned my living doing COBOL...
4
by: Prowler | last post by:
In the application we are currently building, we need to write positioning code on-the-fly, based upon the screen offset of the element in the AS/400 application which drives the Web app. The 400,...
11
by: Colleyville Alan | last post by:
I posted that I was having trouble with a SQL statement that was working in the SQL window, but not in VBA. I have since discovered that when I create the string in VBA it is over 1023 characters...
5
by: WindAndWaves | last post by:
Hi Team The function below searches all the tables in a database. However, if subsearch = true then it searches all the objects listed in a recordset (which are all table names). I thought to...
3
by: Johnny M | last post by:
using Access 2003 Pardon the subject line, but I don't have a better word for this strange behavior (or behavior I don't understand!!!) I have a class module named DepreciationFactor. One of...
4
by: Jon Cosby | last post by:
Someone see why this is? If GaussPrime returns true, the debugger doesn't reach the next line in Factor. It goes directly the next line in the Click event. If false, it goes to the next block until...
37
by: Anony | last post by:
Hi All, I'm trying to chunk a long string SourceString into lines of LineLength using this code: Dim sReturn As String = "" Dim iPos As Integer = 0 Do Until iPos >= SourceString.Length -...
35
by: Thierry Loiseau | last post by:
Hello all, and Happy end year 2005 ! Well, I would like to obtain a list of all JavaScript var statement, With "for...in" perharps ? That is bellow my recent test here, but the problem is...
7
by: magmike | last post by:
I currently have a button once clicked, invokes the following: If Address_Select = -1 Then Forms!ProspectForm!Address = End If However, there are 11 other fields in the subform that i'd like...
18
by: dspfun | last post by:
Hi! The words "expression" and "statement" are often used in C99 and C- textbooks, however, I am not sure of the clear defintion of these words with respect to C. Can somebody provide a sharp...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.