$seq="ACGTGACG";
for ($i=1;$i<=1000;$i++) {
mutate($seq);
print "<div id=\"opseq\">";
print $seq;
print "</div>";
}
In the above php code I have a variable, $seq, which mutates over 1000 cycles. I have surrounded this element with div tags, and have given it the id opseq. What I would like to do is to be able to reach this element and change it every cycle. However in the html output I want the element to stay in the same place and be overwritten during each cycle. I gather that I have to change the element through the dom structure of the document, but as how I can do this i have no idea.
Can anyone help?
Thansk in advance!
csmatyi
continuosly change text element
Moderator: General Moderators
Re: continuosly change text element
Do it with AJAX, or move the mutation code into JavaScript.
Code: Select all
<?php // mutate.php
$dna = $_GET["dna"];
// mutate $dna
echo $new_dna;Code: Select all
<?php $dna = "ACGTGACG"; ?>
<html>
<body>
<div id="opseq"><?=$dna?></div>
<script type="text/javascript">
var dna = "<?=$dna?>";
var ajax = new XMLHttpRequest(); // TODO: support for IE (hint: new ActiveXObject...)
// update the opseq div with the mutation
function mutate() {
ajax.open("GET", "mutate.php?dna=" + dna, false);
ajax.send(null);
document.getElementById("opseq").innerHTML = ajax.responseText;
window.setTimeout(mutate, 1000); // refresh every second
}
window.setTimeout(mutate, 3000); // a delay of 3 seconds before mutating
</script>
</body>
</html>