robert
robert

Reputation: 625

javascript - using a variable in getElementById

How can I use a variable in getElementById

html:

   <td><a href="#" onclick='selectEditActivity("id3319201010153333");'>Click</a></td>

javascript:

function selectEditActivity(pass_id){  
  // this works
  alert(pass_id)
  // this works;
  var A = document.getElementById("id33192010101533333").getAttribute("seq");
  alert(A);
  // but this does not when I use the variable

  var B = document.getElementById(pass_id).getAttribute("seq");
  alert(B);

Upvotes: 0

Views: 1162

Answers (2)

VoteyDisciple
VoteyDisciple

Reputation: 37803

id33192010101533333 is not the same thing as id3319201010153333. One of them has an extra 3 at the end.

Use the same ID in your variable and it'll work fine.

Upvotes: 1

Fr&#233;d&#233;ric Hamidi
Fr&#233;d&#233;ric Hamidi

Reputation: 262939

You're missing a 3 in your onclick handler. It should be:

onclick='selectEditActivity("id33192010101533333");'

Instead of:

onclick='selectEditActivity("id3319201010153333");'

Upvotes: 2

Related Questions