[thelist] Something wrong with replace (javascript)

Amazon Paulo Amazon.Paulo at Amazoniacelular.com.br
Tue Jul 2 16:44:01 CDT 2002


Hello everyone,

I'm having trouble with a simple function. In fact, "replace" is not working
as I thought it was going to... It should (?) replace ALL matches in a
string, but is replacing just the first one.

my code:
<script>
function formatField(fieldName){
	var formatedField = fieldName.replace('x','y');
	fieldName.value = formatedField;
}
</script>
<input type="text" onchange="formatField(this);">

Is something wrong? I've tried many different ways to do it unsuccesful... I
type "xxx" in the field and it returns "yxx".

Paulo Guedes



More information about the thelist mailing list