Jump to content

Recommended Posts

I am using AJAX to populate a <td> value.  I want that <td> value to update a javascript variable on that same page.  Something like the example below.  Is this possible?

 

<td id="test1"</td>

<script>
var testvariable = (id ="test1")
</script>

Link to comment
https://forums.phpfreaks.com/topic/190710-assign-id-to-a-javascript-variable/
Share on other sites

you will want to use document.getElementById("test1") to reference the table cell, and use one of the appropriate properties for that object to access its value. it'll most likely be innerHTML that you're looking to use.

So this should technically work.  Correct?  I know very little about javascript.

 

Thank you for the quick reply.  I don't think I have it right, but here is what I have.

 

var name = document.getElementById('test1').innerHTML;
document.write(name);

if you're not calling that chunk of code after updating the <td> element with AJAX, then it won't have a value, because the element's innerHTML hasn't been updated yet. it would be helpful to see the whole script if you want more help.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.