0

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);
0

2 Answers 2

2

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

onclick='selectEditActivity("id33192010101533333");'

Instead of:

onclick='selectEditActivity("id3319201010153333");'
Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.