facebook

What’s wrong with this code? Variable as array key : CLOSED

  1. MobiOne Archive
  2.  > 
  3. Getting Help – General
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #349148 Reply

    Olly
    Member

    Hi,

    I’m not sure why this doesn’t work? It works if I write a separate line for each key giving it a number, but that’s no good as I don’t want 100s of wasted lines of code when I can simply make the key a variable!

    Here is what I have:

    EDIT – Every time I enter code I get an error?

    #349151 Reply

    Hi Olly,

    Seems that your var i is being considered as an string, so you don’t have and index with value i in your array.

    Try something like:

    $('[id$=showroutine[ ' + i + ' ]]').val(create_routine[i]);
    #349158 Reply

    Olly
    Member

    @support-octavio wrote:

    Hi Olly,

    Seems that your var i is being considered as an string, so you don’t have and index with value i in your array.

    Try something like:

    $('[id$=showroutine[ ' + i + ' ]]').val(create_routine[i]);

    Thank you for your reply but that didn’t work 🙁

    for (var i=0;i<create_routine.length;i++)
     {
     $('[id$=showroutine').val(create_routine[i]);

    Anything else I can try?

    #349159 Reply

    Hi Olly,

    Can you share if there is any error in javascript console? When runing the web SIM, press F12 and Chrome Dev tools will show up, go to Console tab and you’ll see if there’s a syntax error.

    #349161 Reply

    Olly
    Member

    @support-octavio wrote:

    Hi Olly,

    Can you share if there is any error in javascript console? When runing the web SIM, press F12 and Chrome Dev tools will show up, go to Console tab and you’ll see if there’s a syntax error.

    Ok it took a while but I managed to get it working!

    for (var i=0;i<create_routine.length;i++)
     {
     $('[id$=showroutine'+ i).val(create_routine[i]);
    

    Thank you for your help, I’ve been stumped with this one for a while!

    #349173 Reply

    Hi Olly,

    Thanks for closing the loop. From your first code it looked like your showroutine var was an array, that’s why I modified it to use the i value as the array’s index. Anyways, glad it was helpful to know what was the problem.

Viewing 6 posts - 1 through 6 (of 6 total)
Reply To: What’s wrong with this code? Variable as array key : CLOSED

You must be logged in to post in the forum log in