Posts: 3,110
Location: Toronto, Ontario
|
Code:
var text1 = document.getElementById("text1");
This will only get you a reference to the element on the page. It doesn't get you the 'value' property. To get/alter the value, you have to access it (like text1.value).
Therefore, the next line should be rewritten as:
Code:
text1.value = text1.value.replace("&","and");
This will work, but it will not replace all instances of the & (only one at a time). To fix this, change the search string into a regular expression where you can use the 'global' flag:
Code:
text1.value = text1.value.replace(/&/g,"and");
That line in place of yours should make it work as expected.
|