Glaanieboy
OSNN Veteran Addict
- Joined
- 6 Mar 2002
- Messages
- 2,628
I was bored, so I decided to make a javascript which replaces words while typing in a textfield. But I also wanted a counter with it, so I used document.write('Replaced words so far ' + counter), where counter is added up each time a word is replaced. The problem is, it doesn't write, not even the text-bit. Here's the code:
IE (I am at work now, I can't test it with another browser) doesn't give a javascript error, the text is being replaced, yet it doesn't write a thing. I even tried to place a document.write('test'); within the last script brackets, but that doesn't work also, can someone help me?
Code:
<HTML>
<HEAD>
<SCRIPT type="text/javascript">
function checkField(){
text = document.formname.textfield.value;
var counter = 0;
if (text.search('text') != -1){
text = text.replace('text','bleh');
counter++;
}
document.formname.textfield.value = text;
}
</SCRIPT>
</HEAD>
<BODY>
<script type="text/javascript">
if (!counter OR counter == 0){
counter = 'none';
}
document.write('Replaced words so far: '+ counter);
</script>
<form name="formname">
<input type="text" value="" name="textfield" onKeyup="checkField();">
</form>
</BODY>
</HTML>
IE (I am at work now, I can't test it with another browser) doesn't give a javascript error, the text is being replaced, yet it doesn't write a thing. I even tried to place a document.write('test'); within the last script brackets, but that doesn't work also, can someone help me?