I want to move a JavaScript function up to the <script> tag from a input tag and it's not working.
This works:
<input type="text" name="aaa" id="aaa" onkeyup="javascript:this.value=
this.value.substring(0,1).toUpperCase()+
this.value.substring(1,this.value.length);
if (this.value=='')
document.getElementById('aaaLabel').innerHTML='AAA';"
/>
This doesn't:
<script type="text/javascript">
function FieldOnKeyUp() {
this.value=this.value.substring(0,1).toUpperCase()+
this.value.substring(1,this.value.length);
if (this.value=='')
document.getElementById('aaaLabel').innerHTML='AAA';
}
</script>
<input type="text" name="aaa" id="aaa" onkeyup="FieldOnKeyUp()">
What's the difference?
this. You may have better luck of you doonkeyup="FieldOnKeyUp(this)", and then usefunction FieldOnKeyUp(theField)to declare your function. Then replace every instance ofthiswiththeField.