this.id is not working for me

Discussion in 'JavaScript' started by lektrikpuke, Nov 24, 2014.

  1. #1
    
    alert(this.id); // works - displays woodbury when I click on woodbury
    alert(obj.woodbury['xAv']); // works - displays xAv info that pertains to woodbury when clicked
    alert(obj.this.id['xAv']); // does not work when clicked
    
    Code (markup):
    obj is a json decoded var (not sure if that's relevant).

    Help?
     
    Solved! View solution.
    lektrikpuke, Nov 24, 2014 IP
  2. PunctRo

    PunctRo Active Member

    Messages:
    102
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    83
    #2
    Have you tried
    alert(obj.[this.id]['xAv']);
    Code (JavaScript):
    ?
     
    PunctRo, Nov 24, 2014 IP
  3. lektrikpuke

    lektrikpuke Well-Known Member

    Messages:
    297
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    113
    #3
    I tried that and it didn't work, either. =(
     
    lektrikpuke, Nov 24, 2014 IP
  4. sarahk

    sarahk iTamer Staff

    Messages:
    28,821
    Likes Received:
    4,539
    Best Answers:
    123
    Trophy Points:
    665
    #4
    what do you get with
    console.log(this);
    Code (markup):
    I've found that normally dumps the object into the console and makes it easier to see how the data is structured.
     
    sarahk, Nov 24, 2014 IP
  5. #5
    ...and provide more code please. What to be clicked? Just a guess then: assuming that obj.woodbury['xAv'] is the right syntax, then the same value can also be achieved with obj['woodbury']['xAv'] or in other word.... obj[this.id]['xAv'] ???
     
    hdewantara, Nov 24, 2014 IP
  6. lektrikpuke

    lektrikpuke Well-Known Member

    Messages:
    297
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    113
    #6
    console.log gave me pretty much the same feedback as the alerts, but it did add a note saying that 'name was not identified after .' For a lark I tried removing the dot after obj - alert(obj[this.id]['xAv']) and it worked.

    Yeah! =)

    Thanks for your feedback. I must have tried 100 different variants (might be an exaggeration) and then over again. =)
     
    lektrikpuke, Nov 24, 2014 IP
  7. lektrikpuke

    lektrikpuke Well-Known Member

    Messages:
    297
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    113
    #7
    Yeah, that was the ticket. Wish I'd read that before bouncing my head off the wall another hour or so. =)
     
    lektrikpuke, Nov 24, 2014 IP