<!DOCTYPE html >
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>AJAX with PHP: Quickstart</title>
<script type="text/javascript" >
var n = 1;
function testNextPrime() {
var isPrime = true;
n = n + 1;
// console.log('testing', n);
for (var i = 2; i <= Math.sqrt(n); i += 1) {
if (n % i == 0) isPrime = false;
}
if (isPrime) {
document.getElementById("result").innerHTML='n';
// document.getElementById("myDiv").innerHTML
}
// Schedule the next test (this gives browser a chance to update display and process any other events)
setTimeout(testNextPrime, 200);
}
// Start testing for primes
testNextPrime();
</script>
</head>
<body>
<p> I want to update prime number here</p>
<div id="result" >
</div>
</body>
</html>
Hi I tried to update the div tag using above code. if I use document.write(n) instead of document.getElementById("result").innerHTML='n'; I can print the values. What is the wrong with above code?
menukadevinda 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.