2 Replies - 334 Views - Last Post: 12 April 2018 - 05:16 AM

#1 Pogaca   User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 142
  • Joined: 24-August 13

Problem with loop - appending

Posted 12 April 2018 - 12:36 AM

Greetings,

It seems that I have trouble with my loop since it doesn't work as I expect it to do. Here is loop code:

for(var i = 0; i < activeFieldsArr.length;i++) {                           
                                
                            if(activeFieldsArr[i] === "Fax" && activeFieldsArr[i] !== "Website" && activeFieldsArr[i] !== "Customer_Notes" && activeFieldsArr[i] !== "Customer_Code") {                                    
                                $('#sortable1_header1').append("<li  id=customer_fax>" + activeFieldsArr[i] + '</li>');                     
                            } 
                            
                           if(activeFieldsArr[i] === "Website" && activeFieldsArr[i] !== "Fax" && activeFieldsArr[i] !== "Customer_Notes" && activeFieldsArr[i] !== "Customer_Code") {
                               $('#sortable1_header1').append("<li  id=customer_website>" + activeFieldsArr[i] + '</li>');
                           } 
                           
                           if(activeFieldsArr[i] === "Customer_Notes" && activeFieldsArr[i] !== "Fax" && activeFieldsArr[i] !== "Website" && activeFieldsArr[i] !== "Customer_Code") {
                               $('#sortable1_header1').append("<li  id=customer_notes>" + activeFieldsArr[i] + '</li>');
                           } 
                           if(activeFieldsArr[i] === "Customer_Code" && activeFieldsArr[i] !== "Fax" && activeFieldsArr[i] !== "Website" && activeFieldsArr[i] !== "Customer_Notes") {
                               $('#sortable1_header1').append("<li  id=customer_code>" + activeFieldsArr[i] + '</li>');
                           } 
                           
    }


Let me explain a code a bit. activeFieldsArr is real array that may contain values like: Fax. Website, Notes, Code. All string values. Now, I try to loop through all items and to add them inside list in order they are saved before. For some reason loop stops at first finding which is Fax in my case.

Is This A Good Question/Topic? 0
  • +

Replies To: Problem with loop - appending

#2 ndc85430   User is offline

  • I think you'll find it's "Dr"
  • member icon

Reputation: 981
  • View blog
  • Posts: 3,871
  • Joined: 13-June 14

Re: Problem with loop - appending

Posted 12 April 2018 - 01:08 AM

I haven't looked through your code in detail, but one thing I see is that your HTML isn't quite right: remember that attribute values should be in double quotes. For example, the string id=customer_website should really be id="customer_website" (though of course you're going to need to escape the " characters).
Was This Post Helpful? 0
  • +
  • -

#3 Pogaca   User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 142
  • Joined: 24-August 13

Re: Problem with loop - appending

Posted 12 April 2018 - 05:16 AM

I solved the problem like this:

for(var i = 0; i < activeFieldsArr.length;i++) {                           
                                
         if(activeFieldsArr[i] === "Fax") {                                    
                $('#sortable1_header1').append("<li  id=customer_fax>" + activeFieldsArr[i] + '</li>');                     
        } 
                            
        if(activeFieldsArr[i] === "Website") {
                $('#sortable1_header1').append("<li  id=customer_website>" + activeFieldsArr[i] + '</li>');
        } 
                           
        if(activeFieldsArr[i] === "Notes") {
                $('#sortable1_header1').append("<li  id=customer_notes>" + activeFieldsArr[i] + '</li>');
        } 
        if(activeFieldsArr[i] === "Code") {
                $('#sortable1_header1').append("<li  id=customer_code>" + activeFieldsArr[i] + '</li>');
        }
        if(activeFieldsArr[i] === "Name") {
                $('#sortable1').append("<li  id=customer_description>" + activeFieldsArr[i] + '</li>');
        }
        if(activeFieldsArr[i] === "Company") {
                $('#sortable1').append("<li  id=pos_storename>" + activeFieldsArr[i] + '</li>');
        }
        if(activeFieldsArr[i] === "E_mail") {
                $('#sortable1').append("<li  id=customer_email>" + activeFieldsArr[i] + '</li>');
        }
                           
    }    

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1