Hello,
It’s my first time posting here, so please bear with me. I’m taking a beginners web development program and so I’m trying to figure out some of the tricks and skills of javascript. Here’s my issue:
I want to write some very simple javascript where there’s a button you can click, it’ll run some “while” function, and then print the HTML below the button. The way I have it right now though, I click the button and it takes me to a blank HTML document and writes and HTML there, ultimately erasing everything else on the page. Here’s what my code looks like:
[code=php]<button onclick=”countup();”>Click</button>
<script type=”text/javascript”>
function countup() {
i=0
while (i<=10) {
document.write(“<p>” + i + “</p>”);
i++; }
}
</script>
For my assignment for school. I have to display about half a dozen variations of this “while” statement. I wanted to be able to have all the buttons ready and the instructor can just click each one and the HTML will write out below the button clicked.
While I’m at it, is there a way to make the HTML all write out on one line?
Thanks to anyone that takes a look at this. I appreciate your time.