Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
Like Tree2Likes
  • 1 Post By code_generator
  • 1 Post By Old Pedant

Thread: Alert method correction please

  1. #1
    New to the CF scene
    Join Date
    Jul 2014
    Posts
    7
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Alert method correction please

    Hi I am trying to pull all the names. I currently have 13 records with names in it.
    But I am pulling only the first record's name.
    I am using alert method to debug and I see only first record's name. What am I doing wrong and how do I pull all the 13 record's names.
    Please help me..

    if(records!=null && records.results.length>=1)
    {
    for(var i=0;i<records.results.length;i++)
    {
    var securityEntity=records.results[i];
    alert(securityEntity.FullName);
    return securityEntity.FullName;
    }
    }

    Thanks

  • #2
    New Coder
    Join Date
    Jun 2014
    Posts
    23
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Remove that return statement in your for loop............
    Javascriptdev likes this.

  • Users who have thanked code_generator for this post:

    Javascriptdev (07-28-2014)

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,588
    Thanks
    80
    Thanked 4,497 Times in 4,461 Posts
    return means "return RIGHT NOW, do not execute ANY more statements in the current function!".

    And if you think your code is not inside a function, then it effectively means "return from the global code that is currently executing". How that is interpreted will depend on the environment.
    Javascriptdev likes this.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    Javascriptdev (07-28-2014)

  • #4
    New to the CF scene
    Join Date
    Jul 2014
    Posts
    7
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Thank you..

  • #5
    New to the CF scene
    Join Date
    Jul 2014
    Posts
    7
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Thanks OldPedant..
    But still after removing the return statement, I am still not able to alert the values of my arrray one by one.
    I am only seeing first record's value.
    What I found is there is no value(null) in the second record and it is causing it to come out of the loop.
    So I used|| in the if statement instead of &&.
    But then my records length will always be greater than 1 and it won't terminate the loop.
    How can I proceed if my loop doesn't have to terminate for a null value?

    Thanks


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •