utils.js: separate attr and id

I was using the attribute as the object id in the html page.  By
splitting the two, I can have the same attribute set in multiple places
on a single page independently.
This commit is contained in:
Bryan Schumaker 2010-12-27 12:45:23 -05:00
parent 7c7bf03d71
commit 66a637815e
2 changed files with 6 additions and 6 deletions

View File

@ -8,12 +8,12 @@
<tr><td><a href="library.py">Library Browser</a></td></tr> <tr><td><a href="library.py">Library Browser</a></td></tr>
<tr><td><a href="library2.py">Library Browser 2</a></td></tr> <tr><td><a href="library2.py">Library Browser 2</a></td></tr>
<tr><td><a href="controls.html">Remote Controls</a></td></tr> <tr><td><a href="controls.html">Remote Controls</a></td></tr>
<tr><td id="version"></td><td id="uptime"></td></tr> <tr><td id="vers"></td><td id="up"></td></tr>
</table> </table>
<script type="text/javascript"> <script type="text/javascript">
set_attr("version"); set_attr("version", "vers");
set_attr("uptime"); set_attr("uptime", "up");
</script> </script>
</body> </body>

View File

@ -1,19 +1,19 @@
// Bryan Schumaker (12 / 27 / 2010) // Bryan Schumaker (12 / 27 / 2010)
function set_attr(attr) function set_attr(attr, id)
{ {
var req = new XMLHttpRequest(); var req = new XMLHttpRequest();
req.onreadystatechange = function() req.onreadystatechange = function()
{ {
if (req.readyState == 4 && req.status == 200) if (req.readyState == 4 && req.status == 200)
{ {
document.getElementById(attr).innerHTML = req.responseText; document.getElementById(id).innerHTML = req.responseText;
} }
} }
req.open('GET', "controls.py?a=" + attr, true) req.open('GET', "controls.py?a=" + attr, true)
req.send() req.send()
setTimeout("set_attr(\"" + attr + "\")", 3000) setTimeout("set_attr(\"" + attr + "\", \"" + id + "\")", 3000)
} }
function do_request(action) function do_request(action)