cream
cream

Reputation: 1129

Changing onfocus with JavaScript

I have a conditional statement that does this if a condition is met. My if statement is fine, everything else works perfectly. The idea is that if a certain checkbox is ticked, one of the text input will be set to a certain value and become uneditable. I am having problems with this line. Is there a better way to do this? I cannot figure out what's wrong!

document.getElementById('amount').onfocus = "this.blur()";

Upvotes: 1

Views: 353

Answers (2)

João Mosmann
João Mosmann

Reputation: 2902

try

onFocus = function(){return false;}

or you can use the readonly attribute in your input tag. But i'm not sure if it work in all browsers.

Upvotes: 1

Musa
Musa

Reputation: 97672

How about disabling it

document.getElementById('amount').disabled = true;

or making it read only

document.getElementById('amount').readOnly = true;

FIDDLE

Upvotes: 3

Related Questions