mlse
08-14-2005, 10:20 AM
Hi.
I have a requirement to do something which, on the face of it, seems pretty simple!
In it's simplest incarnation, it would just be a button, somewhere on a page, which, when clicked, would cause the content of something else on the page to change.
Here is an example of a noddy piece of code which I wrote to try and do this:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional/EN">
<html>
<head>
<title>"Dynamic Content Test"</title>
<script language="javascript" type="text/javascript">
var counter = 0;
function doIncrement(id)
{
thing = document.getElementByID(id); //Get the thing to be fiddled with.
thing.content = counter; //Fiddle with it.
counter++; //Increment the counter.
}
</script>
</head>
<body>
<input type="button" value="click me" onclick="doIncrement('counter-display');">
<div id="counter-display"></div>
</body>
</html>
What I was hoping for was a web page that starts with a single button on it and nothing else (this is all fine).
When the user first clicks the button, "0" should appear under the button. Subsequent clicks should cause the number under the button to be incremented in steps of 1 each time. This, however, does not happen! All I get in the error tally for the web browser is - "error on line <whatever> (the line it complains about is thing = document.getElementByID(id);) - object does not support this property or method".
I have tried several variations on the theme (all of which seem to be even further from the mark!).
What am I doing wrong?
Thanks,
Mike.
I have a requirement to do something which, on the face of it, seems pretty simple!
In it's simplest incarnation, it would just be a button, somewhere on a page, which, when clicked, would cause the content of something else on the page to change.
Here is an example of a noddy piece of code which I wrote to try and do this:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional/EN">
<html>
<head>
<title>"Dynamic Content Test"</title>
<script language="javascript" type="text/javascript">
var counter = 0;
function doIncrement(id)
{
thing = document.getElementByID(id); //Get the thing to be fiddled with.
thing.content = counter; //Fiddle with it.
counter++; //Increment the counter.
}
</script>
</head>
<body>
<input type="button" value="click me" onclick="doIncrement('counter-display');">
<div id="counter-display"></div>
</body>
</html>
What I was hoping for was a web page that starts with a single button on it and nothing else (this is all fine).
When the user first clicks the button, "0" should appear under the button. Subsequent clicks should cause the number under the button to be incremented in steps of 1 each time. This, however, does not happen! All I get in the error tally for the web browser is - "error on line <whatever> (the line it complains about is thing = document.getElementByID(id);) - object does not support this property or method".
I have tried several variations on the theme (all of which seem to be even further from the mark!).
What am I doing wrong?
Thanks,
Mike.