dlebowski Posted February 2, 2010 Share Posted February 2, 2010 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> Quote Link to comment Share on other sites More sharing options...
akitchin Posted February 2, 2010 Share Posted February 2, 2010 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. Quote Link to comment Share on other sites More sharing options...
dlebowski Posted February 2, 2010 Author Share Posted February 2, 2010 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); Quote Link to comment Share on other sites More sharing options...
akitchin Posted February 2, 2010 Share Posted February 2, 2010 what code are you using to populate the <td> element? Quote Link to comment Share on other sites More sharing options...
dlebowski Posted February 2, 2010 Author Share Posted February 2, 2010 document.getElementById('test1').innerHTML = decodeURIComponent(raw.data.test1); Quote Link to comment Share on other sites More sharing options...
akitchin Posted February 2, 2010 Share Posted February 2, 2010 and is that code working for you? if so, then you should have no problem assigning that innerHTML to a local variable. Quote Link to comment Share on other sites More sharing options...
dlebowski Posted February 2, 2010 Author Share Posted February 2, 2010 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); Quote Link to comment Share on other sites More sharing options...
akitchin Posted February 2, 2010 Share Posted February 2, 2010 it should - have you tried running it? Quote Link to comment Share on other sites More sharing options...
dlebowski Posted February 2, 2010 Author Share Posted February 2, 2010 Yeah. No luck. I will keep working with it. Thanks. Quote Link to comment Share on other sites More sharing options...
akitchin Posted February 2, 2010 Share Posted February 2, 2010 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. Quote Link to comment Share on other sites More sharing options...
dlebowski Posted February 2, 2010 Author Share Posted February 2, 2010 Well, let me mess with it. It's using AJAX Push so that complicates things for me. Thanks again. Ryan Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.