0

I am trying to use jQuery. To update a specific TD with innerHTML I am trying to figure out, how I can catch the value of the parameter.

In this example i need to catch the user-id "1234" so i can update the TD with the ID "status1234".

I am not very familar with javascript, I hope someone can give me a hint.

$(function() {
  $('.ajax-link').click(function() {
    $.get($(this).attr('href'), function(msg) {
      alert("Data Saved: " + msg);
      $("#status" & user).html("some content");
    });
    return false;
  });
});
// TD with Link:

<td id="status1234">
  <a href="/ajax_test.cfm?user=1234" class="ajax-link">Do the Ajax</a>
</td>

Thanx!

1
  • What is $("#status" & user) supposed to mean? & is bit-wise AND, why would you use it with strings? To concatenate strings you use +. Commented Jun 4, 2016 at 10:36

2 Answers 2

1

You may do like this

       $(function() {
  $('.ajax-link').click(function() {
  var user=$(this).data('user');
    $.get("/"+$(this).data('url')+"/user="+user, function(msg) {
      alert("Data Saved: " + msg);
      $("#status" + user).html("some content");
    });
  
  });
   });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<td id="status1234">
      <a data-url="ajax_test.cfm" data-user="1234" class="ajax-link">Do the Ajax</a>
    </td>

Sign up to request clarification or add additional context in comments.

Comments

0

Do this..

$(function() {
   $('.ajax-link').click( function() {
     var userTd = $(this).parent().attr('id');
     $.get( $(this).attr('href'), function(msg) {
          alert( "Data Saved: " + msg );
          $("#"+userTd ).html("some content");
     });
     return false;
  });
});

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.