somedude Posted April 15, 2007 Share Posted April 15, 2007 If i have a loop like this <% For i= 1 to 5 %> <div id="txt<% response.write(i) %>">Hello<% response.write(i) %></div> <% next %> Is it possible to get the value of the div with id txt3? I'm thinking something like this but i don't know the syntax <script> var one=document.getElementById("txt*.* lol ???") .innerHTML alert(one) </script> And no i can't just use getElementById("txt3") because i won't always be needing txt3. This is related to some AJAX work i'm doing. In the function stateChanged() { if (xmlHttp.readyState==4) { document.getElementById("sendvalue").innerHTML=xmlHttp.responseText; } } The value sendvalue is dynamic. The value may be sendvalue1 or sendvalue45. Thanks for any help. Link to comment https://forums.phpfreaks.com/topic/47063-dynamic-div-id-value-can-i-get-the-innerhtml/ Share on other sites More sharing options...
Goose Posted April 15, 2007 Share Posted April 15, 2007 You can access elements by using variables. So for instance if you know that you have 5 elements and the elements are name txt1, txt2, etc. then you can access all of the HTML values of those elements with the following code: var i; var elementHTML; for(i = 1; i <= 5; i++){ elementHTML = document.getElementById('txt' + i).innerHTML; // do something with your elementHTML } Link to comment https://forums.phpfreaks.com/topic/47063-dynamic-div-id-value-can-i-get-the-innerhtml/#findComment-229924 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.